Writing CGI Applications with Perl 250
Writing CGI Applications With Perl | |
author | Kevin Meltzer and Brent Michalski |
pages | 500 |
publisher | Addison Wesley, 2001 |
rating | 9/10 |
reviewer | Dave Cross |
ISBN | 0-201-71014-5 |
summary | Great Introduction To Writing CGI Programs in Perl |
The problem, of course, with most Perl CGI books is that they are written by people who just don't know very much Perl. That's certainly not the case here. Both Kevin and Brent are well-respected members of the Perl community and they know what they are talking about when it comes to writing CGI programs in Perl.
Another common mistake in Perl CGI books is that the authors try to take people who know a bit of HTML and teach them programming, Perl and CGI all at the same time. The authors of this book realise that this approach is likely to lead to, at best, patchy understanding of any of these concepts so they aim there book at people who are already programmers and who have some knowledge of Perl. This means that they can concentrate of teaching the parts of Perl that are useful when writing CGI programs.
One corner that is often cut when discussing CGI programming is security. This is a very dangerous approach to take as a badly written CGI program can leave your web server open to attack from anyone on the Internet. That's not a mistake that is made here as the authors introduce security in chapter 2. Add to that the fact that the code examples all use -w, use strict and CGI.pm and the book is already head and shoulders above most of its competition.
Early chapters look at common CGI requirements such as file uploads and cookies. Each chapter is full of well written (and well-explained) sample code. The example of an access counter in chapter 6 even locks the file containing the current count - this is possibly a first in a Perl CGI book!
By the middle of the book we have already moved beyond simple CGI programming and are looking at mod_perl. This chapter covers both the "faux-CGI" Apache::Registry module and also writing complete mod_perl handlers.
In the second half of the book we start to look at some bigger examples. The authors present a web-based email system and even a shopping cart. In order to fit these examples into their respective chapters a couple of corners have been cut, but there's enough information there to enable anyone to write the complete systems.
Chapter 13 introduces the HTML::Mason module as a way to separate content from presentation. It's obvious that the author's are big fans of this module and this leads to my only real criticism of the book. At no point do they mention the fact that the same benefits can be gained from using any of half a dozen templating systems found on the CPAN. I would have been a lot happier if they had mentioned things like Text::Template, HTML::Template and the Template Toolkit before picking HTML::Mason as the system for their example.
There are then two more long chapters with examples of a document-management system and image-manipulation software. Once more, the code in these examples would serve as a great starting point for anyone wanting to implement something along these lines. The last chapter looks at XML and, in particular, the use of RSS files to provide data feeds to other web sites.
All in all this is a very useful book for someone wanting to write web-based applications using Perl. It's packed full of good advice and code that follows all of the best practices for writing CGI programs in Perl. This book won't teach you Perl, but if you've read Learning Perl or Elements of Programming with Perl then you'll find this book easy enough to follow.
You can purchase Writing CGI Applications with Perl from bn.com. Slashdot welcomes readers' book reviews -- to submit yours, read the book review guidelines, then hit the submission page.
24 Hours (Score:2, Insightful)
got all the basics and enough to start on cgi... evan if you don't know perl to start with...
Re:24 Hours (Score:1, Troll)
Re:24 Hours (Score:3, Informative)
"A set of rules that describe how a Web Server communicates with another piece of software on the same machine, and how the other piece of software (the 'CGI program') talks to the web server."
This also makes PHP use CGI, so your comment is somewhat akin to saying "Windows is dead! Use Windows 2000!" or something equally thoughtless and banal.
As far as concerns intuitive, what do you mean? It's easier to learn? Or do you mean you can guess at writing it? Time to find a dictionary, young Jedi.
But, assuming you hadn't been talking utter nonsence, a quick look at jobserve, one of the biggest UK jobs sites, shows 812 ASP-related jobs, 351 Perl-related jobs, and 70 PHP-related jobs.
So, what *exactly* are you basing your ignorant comments on?
Re:24 Hours (Score:2)
Common Gateway Interface (CGI) is a specific [uiuc.edu] interface between web server and code. This interface relies on a "shelling" style system.
PHP does not use CGI neither does ASP. By your own statement you state "A set of rules that describe how a Web Server communicates with another piece of software on the same machine..." oblivious to the fact that neither ASP, PHP or any of the modern decent languages comply with these "rules".
Both environments utilise intstructions within the HTML code that are recognised and subsequently executed by interpreters often loaded in the web server application space.
They DO NOT rely on environment variables, command lines and input/output files all of which are part of the CGI standard. CGI is quite rightly on it's last legs because shelling out to executables is both a security risk and processor intensive.
Perhaps you should be more careful what you are basing your ignorant comments on.
Re:BUT ... cgi is extremely powerful. (Score:2)
Re:BUT ... cgi is extremely powerful. (Score:2)
Re:24 Hours (Score:2)
Common Gateway Interface is, yes, "a set of rules that describe...", but note the indefinite article in your definition. There are, young jedi, other sets of rules as well, and PHP and ASP, among others, use those other interfaces. To continue your analogy, "Windows 2000 is a software layer between applications and hardware, and Unix is a layer between applications and hardware, so...Unix is Windows!"
(Oh, and if you're going to quote so plonkingly, would you mind citing the quotation? If you're quoting your bother-in-law the butcher, that's a little different from quoting an RFC.)
Re:24 Hours (Score:2)
To continue your analogy, "Windows 2000 is a software layer between applications and hardware, and Unix is a layer between applications and hardware, so...Unix is Windows!"
actually they are both operating systems.
[golux.com]
The Common Gateway Interface (CGI) is a simple interface for running external programs, software or gateways under an information server in a platform-independent manner. Currently, the supported information servers are HTTP servers.
Re:24 Hours (Score:2)
Thank you, BTW, for citing your source. It doesn't change sheriff_p's point, since the issue wasn't so much that his definition was wrong -- it wasn't, just not as complete as he apparently thought -- but that he made such a big deal out of it ("and I quote", he says, but doesn't get around to telling us whom he's quoting)
Re:24 Hours (Score:2)
Brother, you seem to have a beam in your eye.
Although it is possible to compile PHP to use the Common Gateway Interface, this is extremely rarely done (I do still have one server on which it is done, but that's because that particular server has had no software change since 1996). Almost all PHP is now run in process (as, indeed, can PERL be scripts if you use Apache's mod_perl). The Common Gateway Interface is now very rarely used in professional or production projects, although it remains appropriate for quick'n'dirty hacks.
... and 2002 Java related jobs, of which the majority will be server-side. So you're comprehensively wrong on all points.
CGI is, indeed, " A set of rules that describe how a Web Server communicates with another piece of software on the same machine, and how the other piece of software (the 'CGI program') talks to the web server." However, it isn't the only set of rules or the best set of rules, and most server-side dynamic content is now produced in-process one way or another. CGI is just too inefficient for production use.
Re:24 Hours (Score:3, Insightful)
i speak from expirence here. about a year ago i made the switch from php to perl and i haven't been happier. at the time of leaving the only database abstraction layer was in beta while perl had dbi in a quite stable form.
while i realize the parent was probably a troll, i would strongly encourage people considering php vs (perl, python, etc.) to consider the amount of code already available outside of the base distribution of the scripting language.
Re:24 Hours (Score:4, Insightful)
Re:24 Hours (Score:1)
makes a good reference though....
Re:24 Hours (Score:1)
Ok, while I agree that Perl is easy to learn, one should be carefull to call himself a programmer afther reading one of these book.
Obviously, if you get down to programming CGI in one day, how can you know all the pitfalls you will have to avoid in order to make your CGI secure?
So many scripts are flawed or even dangerous. Just look at the (popular) pile of crap that is Matt's Script Archive. Those CGI aren't even programmed with CGI.pm, they are badly designed, and aimed at non-programmers that will install them on their servers, not knowing much more than they have to make the script executable so it will run.
Programming CGIs should always be done with great care, and is a task best left in the hands of professionals.
Re:24 Hours (Score:5, Informative)
nms [sourceforge.net] is such a place. It has replacements for all of Matt's scripts - and Matt himself has suggested using them as replacements for his buggy versions
I'm sure the author of this review would agree with me that this is a good place to go to get scripts ;-)
Strict (Score:2)
Also, what's wrong with Mason? They may have recommended it because it makes an easy transition into mod_perl, as it can be used either way.
Re:Strict (Score:1, Informative)
Yeah, that's covered in great depth the section on security that I mentioned in the review.
Oh, nothing. It's just that I would rather not have had it presented as the only templating solution.
Re:Strict (Score:2, Informative)
Uh, what? (Score:5, Insightful)
Speaking of classics, the old "Writing Web Clients with Perl" is being superseded this month by Sean Burke's "Perl and LWP". Now speaking of Perl studs, they don't get much studlier than Sean, and LWP is (IMHO) the Killer App for Perl programmers. Another fine O'Reilly title (too bad "fine O'Reilly title" is not redundant anymore).
Also from O'Reilly (yawn) is Rasmus Lerdorf's "Programming PHP". I was *very* pleasantly surprised by his book, it is MUCH better than it has any right to be, discussing everything from PEAR DB abstraction classes to speeding up your site with a Squid reverse cache and profiling.
Anyways, that's just my shelf's worth. I use Perl and PHP every day (or at least every day I wear my programmer hat) to get things done fast. I know other people prefer Python and Ruby, hey, more power to them. But I figured I would point out some Fine O'Reilly Titles (note, once again, that phrase is now said more like "Honest Senator" rather than "Stupid Microsoft Security Hole") which have made me some money lately.
YMMV...
Re:Uh, what? (Score:2)
Re:Uh, what? (Score:3, Interesting)
Not a flame, just an observation. Apache::Registry is not a panacea.
Re:Uh, what? (Score:3, Informative)
Re:Uh, what? (Score:2)
Not reading the article - bad; not reading the writeup at the top of the page before commenting -- very bad; -1 redundant post moderated up to 5: mind-blowing. Moderators, if you can't be arsed to read the article, don't moderate! Sheesh...
You missed both of my points (Score:2)
1) shown you how to fit the pieces of Apache together,
2) written sample code for 3 of the 7 standard phases of the Apache request cycle, and
3) actually given you some insight into how to extend Apache for other purposes.
Lincoln used to write CGI scripts. He wrote CGI.pm, in fact. Don't you think the fact that he wrote his most notable programming book on mod_perl is a telltale sign of what I find wrong with this book AND the review?
And that witty riposte -- my god! I've never in my entire life heard that one before! Quick, somebody get Jerry Seinfeld's agent on the phone.
I can be 'arsed' to read an article and (gasp!) form an opinion about it based on my own experience... 7 solid years of it, in this field. And looking back (with the current toolset) I would not want to see ANYONE start off re-inventing the wheel with Perl CGI scripts. Hell, if you're going to re-invent the wheel, at least make it round. CGI is, was, and will always be a kludge. Apache::Registry is a kludge to shoehorn CGI kludgers into the Better Way. Personally, I'd rather see people start out with PHP, because even if their code looks like trash, at least I can write a parser to fix it.
End of rant.
Re:You missed both of my points (Score:2)
What, you don't think that using shell environment variables is a natural way to access http request information?
CGI.pm breakage (Score:2)
However, it's even simpler (and faster) with PHP and that's one reason why I switched. When I first started using Perl for CGI scripts I wrote my own damn CGI %ENV{$foo} de-HTTP-encoder and for the longest time I couldn't understand why CGI.pm was so bloated (truthfully, I kind of still don't). But if you only use specific methods (use CGI.pm qw (foo bar baz); ) then it works OK.
Like I said, I switched to PHP for this and other reasons. I still use Perl on the back end, but for volatile user-interface code, it's all PHP. I think it's a maintenance trap to use Perl if you're ever likely to hand the code over to another engineer, or (worse) do something else for a few months, then come back and try to extend it.
YMMV.
Re:Uh, what? (Score:2)
I wrote a book, with a co-author, on PHP that was released about the same time Programming PHP was. Nothing against Programming PHP, it is a nice book. I read it cover to cover. It has strengths and weaknesses. But I think the book I wrote stacks up at least as well as Programming PHP, yet it is practically invisible because of the O'Reilly open source factor.
Don't take this as me saying, "my book is the greatest thing since sliced bread",or anything like that. My book does not cover extending PHP in C, among a couple of other topics it really should have covered. But it does cover database abstraction using Pear DB. Also covered is Image manipulation, creating PDF documents, XML, almost everything a professional PHP programmer would encounter. Yet, the PHP book had very high visibility before it was even out! Anyways, don't take this post as cynical or jaded about my book not having the high visiblity etc., I wrote the book for the love of it, not for the money.
A quick and interesting aside, Rasmus did not write a majority of the book yet he always gets the credit for Programming PHP
Jeremy
Re:Uh, what? (Score:2)
This explains a great deal of why it didn't suck. I had a sneaking suspicion that was the case.
Bummer about your book getting spined
It just doesn't sound (to me) like the reviewed book is an example of the caliber of competition needed. YMMV.
Not saved, *made* (Score:2)
So, in the span of an afternoon, and over the next few months, my design + your book made us a large pile of cash. Ask someone at CNN, C-SPAN, NBC, FOX, or Bloomberg how they like the interface...
The O'Reilly Problem (Score:2)
mod_perl books (Score:3, Insightful)
A classic, and no longer the only book in the field. mod_perl Developer's Cookbook [modperlcookbook.org] is a tremendous tome, and I use it more than the the LDS/DOUGM book. It's well worth looking at.
It's not better than the eagle book, but if I could only buy one, that would be it.
Most hosts will set up PHP for you, though (Score:2)
I don't see the point of CGI anymore.
Ummm, no... (Score:2)
I have no idea what you've been doing with php, but to claim that mod_php is "like mod_perl" is one of the most ludicrous things I've recently heard. The only way mod_php is "like" mod_perl is that it's an Apache module (most of the time...).
mod_perl is much more powerful (and dangerous).
PHP code running under mod_php is SLOWER than a mod_perl handler. The big win comes in terms of development and maintenance (and portability).
If you want to use Perl, please do so, but don't go implying that mod_perl's functionality is identical to mod_php. That's very misleading.
You should take your own advice (Score:2)
Re:You should take your own advice (Score:2)
Lincoln Stein did, and I think it's an awful lot better and more useful than a book that misleads people into thinking that a kludge like CGI is still a good idea. He and Doug Eachern also waste time on obsolete languages like C, which of course no one would want to use, and the Apache module API, which mod_perl is just a thin layer over.
Can't you dipshits take advice? I make $15K a DAY when my company pimps out my custom programming skills. You think I get paid like that because I can't read? All I'm trying to do here is save other people from making mistakes I made 4 YEARS AGO since, nowadays, they're obvious.
Perl for CGI? why? (Score:1)
Because Perl is more powerful (Score:2, Insightful)
Translating your question into client side programming speak:
"Why use Visual C++ when you can just use Visual Basic?"
Of course, thanks to
Perl is a powerful language with far more backing than PHP, Python, or Ruby. The amount of modules you can get for Perl makes it a very wise language to use if you want to do anything advanced.. i.e. XML-RPC, SOAP, image manipulation on the fly, system integration, etc.
PHP cannot do many of these things well.. and it cannot do them very quickly. PHP is a toy language for kiddies who are still playing with MySQL databases
Re:Because Perl is more powerful (Score:2)
I recently started learning Perl/CGI, just for S&Gs to use on some hobby web sites I'm thinking of developing. I realized that a lot of what I was doing in Perl w/CGI I could do just as easily, and in many cases in fewer lines, in PHP. I already knew PHP so I ended up using PHP instead of Perl.
I think that Perl is still best used for it's original purpose, as Operating System "glue". It's great for system admin tasks, parsing through many lines of text, etc... PHP is better for rapid website development.
PS Visual C++.NET is still more powerful than VB.NET since it allows you to use pointers and manipulate the memory directly. So the hierarchy of power in
VC++.NET
C#.NET
VB.NET
at least from what I can tell.
Re:Because Perl is more powerful (Score:2)
PHP is great when you want to quick and dirty mix code and HTML. As such is serves a purpose.
If you try to separate content and presentation, fine, it can be done, but it's not the natural strength of the language.
Perl's natural strength, in my opinion, is in writing routines that process textual data. PHP's natural applications are, in a sense, a subset of these, when you want to do this in the context of HTML.
Python is not as convenient as Perl for processing data, and much less convenient than PHP for web programming, but better perhaps for generation complex systems of objects, particularly persistent ones.
Re:Perl for CGI? why? (Score:3, Informative)
You hit the nail on the head.
I run web sites on four machines. The one sitting in my home office is the only one where I'm the admin, and the ISP blocks port 80 on that one (not that this is a real problem, but
After experiments with PHP and Python, I've pretty much settled on perl for almost everything, with a few C programs as helpers. My perl CGI scripts run on all the machines without any changes, as do my C programs. With PHP and Python, I've found that every new machine requires a debug session to get anything to work, and I have to maintain huge sets of diffs for the different machines.
But with perl, I can drop a new script in all my directories, and they just work. I have exactly one "per-machine" file CGI file, which lists the directories in which things are installed. Even that isn't necessary, but it's faster than the code to discover where things are.
On one of my web sites, they still have perl 4, and my CGI scripts work fine. I can't install a current perl release, because my disk space there isn't enough to hold the unpacked perl source.
Also, all the timing tests I've been able to run have given perl a substantial edge over everything else except C. But this is a small sample set, due to the difficulties in matching perl's capabilities in PHP (and the difficulties getting a recent Python version installed
It would be nice to be able to depend on mod_perl, but the admins on several of these machines don't see the need for it. Even at several requests per second, my perl CGI scripts are an unmeasurable load on the machine. So why should the admins waste their time installing mod_perl for me, when it would only save a few seconds of cpu time per day?
Re:Perl for CGI? why? (Score:2)
The primary mode of PHP development is to mix code within your html. This works for small or single purpose applications but sucks if you want to develop a server app that uses several different sets of templates customized for different users.
Re:Perl for CGI? why? (Score:2)
I can see why they chose Mason (Score:3, Insightful)
It'd be my first choice for including in a general book as although it can get more complex (and powerful) when necessary it is actually very easy to use for simple sites.
However yes to be fair you'd not want to ignore the very good work done by other module authors.
CGI isn't used much anymore... (Score:4, Informative)
Hate to sound like a "*BSD is Dead" troll, but CGI is a dying breed (NOT PERL, just CGI). I'd suggest skipping this book in lew of a more popular web-app language.
Re:CGI isn't used much anymore... (Score:2, Insightful)
As I said in another post, since you can run Perl CGI scripts in mod_perl (i.e. with perl built directly into Apache itself) the stuff covered in this book is still quite useful. Many powerful sites (including this one) use mod_perl, and it's a good skill to learn...starting off with CGI programming is one good way to start to go about that.
Re:CGI isn't used much anymore... (Score:2)
isn't CGI the generic standard? Possibly, "Perl CGI" is less used than it used to be, (which is an interesting groundshift, one of the first non-MS developments that I'm behind the curve on--PHP seems really kludgey in parts to me, though I respect its builtin libraries) but I think just about every form in HTML points to a "Common Gateway Interface" script, you know, the thing about POSTs and GETs.
Re:CGI isn't used much anymore... (Score:2)
CGI is CGI. Perl has mod_perl, so it is on par with PHP. I'd really love to see mod_scheme. Scheme is perfect, IMO, because the ease of use and the base language, R5RS, has very useful functions which are perfect for web use. All that would be needed is an addon library to make the language a little more complete. Of course there is always mod_python, which I've heard is Lisp/Scheme-like.
Re:CGI isn't used much anymore... (Score:2, Insightful)
Re:CGI isn't used much anymore... (Score:3, Interesting)
For a while there I was giving ASP a try. But 80% of the time, I would do the little project in ASP, and then a couple weeks later I'd get a request for more and more advanced features which were either impossible in ASP, or much much more realistic in a real Perl CGI application. Inevitably I'd have to rewrite the application in Perl for any real power.
I'll stick to Perl CGI.
Re:CGI isn't used much anymore... (Score:2)
Re:CGI isn't used much anymore... (Score:2)
I can't see why you'd want to go Perl CGI when you could go PerlScript ASP.
CPAN. Does PerlScript use CPAN? If not, the primary advantage of Perl (for me) is lost.
+1, informative (Score:2)
I didn't realize it was ActiveState Perl. That's good. PPM is pretty good, from what I hear.
Re:CGI isn't used much anymore... (Score:4, Informative)
It's a shame that PHP has this reputation for only being good for 'quick and dirty' projects. I guess it is because there is so much badly hacked together PHP code available on the web. Or perhaps it's the "it can't be good - it's free" meme.
I have come across a couple of CTOs who are put off PHP by its reputation, which is a real shame. They think it is a toy language and not suitable for large commercial projects. However, the reality is that PHP is now an extremely well designed and advanced language, and good for even very large projects. It has some extremely competent techies working on it. It is also well maintained and advancing rapidly. So, if you don't fancy PHP because of its reputation, I suggest you take another look at it.
Agreed - PHP can be advanced (Score:2)
Yes this is primarily a shameless plug, but rather than just saying 'PHP is not a toy' I figured I'd give an actual example.
PHP and large scale projects (Score:2)
I agree that a lot of people underestimate PHP, which is excellent, but it is a tool for a job. imho it's for small to medium-large projects. I'm not sure I would recommend it for a seriously large project though.
Phillip.
Re:CGI isn't used much anymore... (Score:2)
what is your definition of a toy language?
Re:CGI isn't used much anymore... (Score:2)
Also, I found the error messages a lot less helpful than with some other languages.
Re:CGI isn't used much anymore... (Score:2)
For instance?
I agree that the error messages are a bit obtuse at times, but that doesn't make it a toy language.
Re:CGI isn't used much anymore... (Score:2, Informative)
That and ridiculous scoping rules (having to import globals into local functions? Huh? Isn't that why I made them global to begin with?) lead me to deeply distrust it as a sturdy development platform.
Re:CGI isn't used much anymore... (Score:2)
For instance, the way each() and all that uses a pointer that's part of the array, and you need to call reset() on the array if you want to iterate over it twice! In general, side effects like that aren't considered a positive part of a language.
This is kind of fixed if you use foreach() instead, and I found a bug in the docs, where it said using each() was the equivalent of foreach()...similarly, there was a bug when I was walking one array inside another array using each(), it would stop after the first outerloop. Using foreach() fixed it.
That kind of thing is just ridiculous in a language that wants to be considered ready for primetime.
Re:CGI isn't used much anymore... (Score:3, Insightful)
But it will never go away entirely. For a lot of simple things CGI is quite appropriate. At work, we have a feed monitoring utility that just generates tables of timestamps. I have very rarely seen it fail. And when it does, it doesn't happen twice in a row unless there's something wrong with the database or the web server. For something mission-critical like your feed monitoring utility you don't want some stateful enterprise application amorphous cloud super server to get it's tentacles in a tangle. CGI is very easy to use, understand, and debug. Don't rule it out alltogether. It's just a tool for niche stateless applications.
Re:CGI isn't used much anymore... (Score:2)
Re:CGI isn't used much anymore... (Score:3, Informative)
Who's the troll?
You can write ISAPI Perl, use Perl in ASP scripts, and create .NET components in Perl, among other options.
As an alternative to Perl...... (Score:3, Informative)
Yet, I've found myself writing more and more smaller apps using PHP [php.net] instead of perl. It's by the Apache group and essentially merges into the www server, making it very quick. You can still use mod_perl for perl apps.
Along with your preferred SQL database, progranmming in PHP is a breeze. Basically, write html pages and add the commands you need embedded inside. The best PHP book I have on that topic is PHP and MySQL Web Development [amazon.com] (ISBN: 0672317842) second to none.
Re:As an alternative to Perl...... (Score:1)
And yes, templating systems do scale. The code that runs this site uses the Template Toolkit - there's even a section in the Slash ORA book on it.
Re:As an alternative to Perl...... (Score:2)
Of course, there's more than one way to do it ;-) And more than one templating system - pick the best one for the job at hand.
Re:As an alternative to Perl...... (Score:2)
Re:As an alternative to Perl...... (Score:2)
Even PHP isn't much of a step up (Score:2, Interesting)
PHP suffers from the same issues as JSP when it comes to building webapps and toys. It's also not really the most efficient system around either.
Much as I love Perl, and have always enjoyed knocking out CGI systems - including one of the first "fansite"s which offered people free custom emails and URLs (warbirds.org), and I've had lots of fun with PHP, I have personally found Roxen [roxen.com]s built in RXML mark-up language to be one of the most efficient systems for developing web applications in terms of design, implementation and operation.
Roxen was born "Spinner" back around, if not before. In all those years since, I've yet to find a good or compelling reason to use Apache, Perl or PHP instead of Roxen beyond the head-count factor. The Roxen developers make their money through 'value adding' their open source webserver platform, but never really tried to market themselves.
OT: Perl... (Score:2, Funny)
You can call me a twisted pervert, but I just can't wait until I sit in front of my future Debian GNU/Hurd 4.0+ system to hack some insane Perl 6 code, drinking espresso and listening to The Ride of the Valkyrie of Richard Wagner...
I've got this book (Score:5, Informative)
Need to hack up some code fast? This book will help. If you really want to learn CGI, to know why and how it works, to have a broader grounding in the technologies used with it, and to build a firm foundation for future self-teaching, then IMHO nothing beats the Mouse book.
mouse book (Score:2)
Writing CGI apps in PERL... (Score:2)
Re:Writing CGI apps in PERL... (Score:2, Insightful)
For a bunch of secure well-written CGI programs for specific tasks, you can't beat nms [sourceforge.net]. Hope this helps.
Re:Writing CGI apps in PERL... (Score:2)
<?php
require(mylib.php);
preprocess_request($HTTP_REQUEST_VARS);
?>
<htm
<body>
<h1>Welcome, <?php get_username(); ?> </h1>
<h2>This is my html page!</h2>
Here is something cool and dynamically generated:
<?php
* but don't do it inline
* call myfunction()
* that's what require() is for
*
* namespaces are a bit of a problem, but you
* can translate all the get, post, session,
* and cookie stuff at the beginning of each
* script -- see preprocess_request().
*/
?>
<h3> I hope you enjoyed my page </h3>
<?php include ("footer.html"); ?>
</body>
</html>
More "expert" chapters (Score:2)
This is a big one for me. As a programmer, it has become increasingly difficult to compete with hackjobs out there. Anyone can pick up a book and begin writing Perl CGI or PHP websites, but not everyone has the experience to secure those systems, or to identify bad code design that leaves built-in vulnerabilities. With some companies this is hard to convey -- well, when you are proposing a $25,000 solution and there is another company willing to do it for $5,000. Nevermind that they have two programmers on their staff willing to make $20,000 this year each and they have been programming off and on for a couple of years, but they like making web pages!
Re:More "expert" chapters (Score:2)
Good book, but not enough detail...not a reference (Score:2, Informative)
I did find the information on mod_perl, HTML::Mason, and RSS to be especially interesting.
If you are looking for an introduction to developing web apps with perl this book presents a large number of technologies, and does a pretty good job. It definitly is not a reference, however.
Coming from an ASP background (Score:3, Interesting)
Both books show how to run CGI programs under a mod_perl enabled web server, using Apache::Registry. So the myth of the server forking a new process for each request is not true. CGI and Perl in this day and age can actually run rings around an ASP solution without the performance hit CGI applications are known for causing.
I know Perl has a lot of detractors, but really you should at least give it a chance before you make up your mind about it. Perl is probably more portable than even Java, and it certainly is better for writing quick scripts and programs. You can make the code very readable if thats your goal, or you can express in one line of code what it would take other languages 5-10 lines to accomplish. Perl/CGI is the most portable way to write web apps so if you do consulting its a good way to go if you need things that will run on lots of different web servers. I've found the neatest libraries for Perl that I haven't seen in any other language - I just wrote a shopping cart that uses SQL to read and write to comma delimited text files! This made for a perfect solution for my client, and it will be easy to upgrade to a real database when he's ready.
Oh by the way if you don't think Perl/CGI can handle heavy duty web sites, look at the slashcode sometime - unless they rewrote everything its still CGI code running under mod_perl/Apache::Registry.
Finish this book... (Score:3, Interesting)
Re:Finish this book... (Score:3, Informative)
I'd agree that the mod_perl Developer's Cookbook [modperlcookbook.org] is really good, and you'll have to prise it from my dead hands before I'll give up my copy.
Frameworks and Perl Criticism (Score:3, Insightful)
There are so many ways to write dynamic Web programs in Perl: embed Perl into your HTML (embperl), embed HTML into your Perl, use a templating system (HTML::Template, Mason, Template Toolkit, etc), mod_perl, and various combinations.
In the end, I think this is a good thing. It means more choices and better adaptability for various situations. However, it can discourage new users of the language that can quickly write CGI programs in Perl, but wind up writing bad programs.
For anyone looking for a Perl CGI framework, I highly encourage you to check out CGI::Application on CPAN. It integrates with HTML::Template, is lighweight, and makes it relatively easy to mod_perl-ify your code if you need performance boosts.
-Will
Re:Frameworks and Perl Criticism (Score:3, Insightful)
One language glues together a web server and a database nicely. You could do something similar with Java using Jakarta and Tomcat [apache.org] if you are prefer Java. Both ways are terrific ways to expand your content delivery.
Perl and CGI? (Score:4, Funny)
Muahahaaahaa (Score:2, Insightful)
But, I find that if I want to do dynamic content, HTML::Mason is much better (for me at least). I can embed the Perl right into the HTML, plus Mason has a lot of other nice features that make it worthwhile.
Plus, I am having a lot of fun reading all of the comments generated by this discussion.
It really amazes me how people basically say things like "Well, I use X for this so everyone else should too"... The key to being a good web developer is using the right tool for the job AS WELL AS utilizing the tools available to you. you also need to take into account what you are better at. I am a Perl developer, sure, I could choose to write apps in C, Java, PHP, Ruby, whatnot, but then I am not utilizing MY talents to their fullest.
Lots -O- flame-bait in these discussions, that is for sure...
Brent
Re:Perl is for girls (Score:1)
Re:Perl is for girls (Score:1)
It can be used with databases just as well as php or asp. I use it with interbase and find it very effierent... on a server that would never run php / asp script becuase of the requriemnts...
Re:does the other way work (Score:1)
(apologies to the Pricess Bride)
CGI is a interface. A Common Gateway Interface. It's a way computer programs (e.g. Perl) can be run so that their output is sent to a browser as a webpage. So yes, writing CGI Applications in Perl makes sense. The other way round does not.
Re:Who uses Perl/CGI anymore? (Score:5, Informative)
The key is that you can easily run CGI scripts - quite possibly unmodified - with mod_perl thanks to the wonders of the Apache::Registry module that ships with mod_perl. It's all covered in the guide. [apache.org]
Re:Who uses Perl/CGI anymore? (Score:2)
Re:Holy modules (Score:1)
Re:Perl is not maintainable... (Score:4, Insightful)
"It's time to get rid of japanese because of its ugly syntax".
If you don't know the language, you shouldn't be maintaining it.
Perl is quite elegant, and the $ # % all make sense. If you know Perl.
Re:Perl is not maintainable... (Score:2, Insightful)
Re:Perl is not maintainable... (Score:2)
I'm not sure I'd class Perl as being elegant. It's very overcomplex and convoluted to my eye.
Simple things like creating classes, passing large data structures about, gracefully handling error situations, even handling argument lists for subroutines, all require either too much code or too many
I do admit to seeing some degree of elegance in the whole @foo[] thing, but I'm growing increasingly alergic to touching native data structures directly, so the use of syntax to denote context and type is rapidly loosing it's appeal.
That's not to say I hate Perl, but I do find myself using Ruby for almost all the situations I'd normally use Perl. The resulting code is usually at least as concise and much cleaner. I can't say I miss it, but I don't hate it's very existance like I do VB
Re:Perl is not maintainable... (Score:2)
"Enterprise suited" (Score:2)
What, pray tell, does this mean? I have heard people tell me that they thought that perl was not "enterprise ready." When I asked them what that meant I got highly-subjective and conflicting answers.
Is the charge that perl is not "enterprise ready" just manager-speak for expressing the prejudiced opinion that perl is merely a "hacker tool"?
Re:I have to take issue with this: (Score:2)
Puctuation does not make languages similar!!!
Re:Microsoft confirms the truth: Perl is dying (Score:2, Informative)
Re:500 pages? (Score:2, Insightful)
This book was designed to be a learning tool, with practical examples.
My goal with the writing that I did was to provide concrete examples people could use and learn from, directly. I have seen too many books that show a concept and then explain a bit about it, but NEVER really show you how to duplicate it. Instead, every line of code is explained so that the reader can see how and why it works.
Sure, if you are comfortable with Perl and writing CGI's, this book is probably not for you...
Also, those people saying CGI's are dead. Um, heh, ok - think what you will...
Brent
Re:Web apps with Java - silly thought? (Score:2)
Well, Tomcat is perfectly free.
As far as strong typing and strings, if you aren't using a strongly typed language you are doing a tremendous amount of debugging by hand that should be handled by your compiler. Also by disregarding Java you are also throwing away a tremendous body of web related libraries and frameworks, plus support facilities like JUnit and JMeter that are part of the Apache Jakarta project.
Finally, if you want the ultimate reason, do a job search and look at the number of Java positions vs. Perl positions.