Can you recommend a book for perl/cgi?

Grant McLean Grantm at web.co.nz
Wed Dec 4 19:58:48 CST 2002


Hi Doug

I've done the odd bit of web programming but when I started
there were no books.  There's a very low threshold to getting 
started.  For example, this is a fully functional CGI program:

#!/usr/local/bin/perl -w

my $now = localtime();

print <<EOF
Content-type: text/html

<html>
<head>
  <title>Hello World</title>
</head>
<body>
  <p>The time is now: $now</p>
</body>
</html>
EOF

Drop it in your web server's CGI-bin directory, make it 
executable, point your browser at it and you're away.

Some tips:

* Once you get on to processing forms and query strings,
  use CGI.pm to handle that side of things - don't try
  to roll your own parameter handling code.

* 'use CGI::Carp qw(fatalsToBrowser);' can save you a
  lot of stress when your script contains errors (of 
  course you'd save even more stress by not writing
  scripts with errors in the first place).

* CGI.pm provides functions for generating HTML - I have
  not found them to be useful and people smarter than me
  recommend against using them. (see also next point).

* Once you've gotten past the toy scripts, you'll want to
  separate content from logic (ie: unlike my script above,
  you should aim to have close to zero HTML in your code).
  I have used the Template Toolkit (from CPAN) and swear
  by it.  Other people like HTML::Template.

* If you're lucky enough to be using Apache, find out about
  mod_perl and use it.  O'Reilly's "Writing Apache Modules
  in Perl and C" by Doug MacEachern (Mr mod_perl) and Lincoln
  Stein (Mr CGI.pm) is excellent.

* mod_perl will open up the possibility of other templating
  systems including Mason, embperl and Apache::ASP.

* If you're using XML, you might want to look at AxKit.

* Ask questions on this list.

* Visit PerlMonks (http://www.perlmonks.org)

* Have fun.

Cheers
Grant

===============================================================
Grant McLean        BearingPoint Inc - formerly The Web Limited
+64 4 495 9026           Level 6, 20 Customhouse Quay, Box 1195
gmclean at bearingpoint.biz                Wellington, New Zealand




> -----Original Message-----
> From: Doug Hendricks [mailto:Doug.Hendricks at tnzi.com]
> Sent: Thursday, December 05, 2002 2:30 PM
> To: wellington-pm-list at pm.org
> Subject: Can you recommend a book for perl/cgi?
> 
> 
> 
> Hello, Wellington.
> 
> I've been using Perl 5, both OO and non-OO, for a few years 
> now and am fairly confident.
> I know *nothing* about web programming -- I use Perl as a 
> general-purpose application language and for scripting.
> I may need to upskill to server-side web programming soon, 
> maybe mostly cgi stuff (not sure yet).
> 
> What modern books can you recommend?
> 
> I have a comp-sci/engineering background, so dense/academic 
> books are acceptable (but not required).
> 
> I am already interested in "Writing CGI Applications with 
> Perl" by Meltzer and Michalski.  Is it good?
> 
> Sincerely yours,
> Doug Hendricks
> 
> 
> 



More information about the Wellington-pm mailing list