Skip to Main Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced content levelIntermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

CGI::Carp

use CGI::Carp;
warn "This is a complaint";     # Stamp it with progname and date.
die "But this one is serious";  # But don't cause server 500 errors.

use CGI::Carp qw(carpout);      # Import this function.
open(LOG, ">>/var/tmp/mycgi-log")
    or die "Can't append to mycgi-log: $!\n";
carpout(*LOG);                  # Now uses program-specific errlog.

use CGI::Carp qw(fatalsToBrowser);
die "Fatal error messages are now sent to browser, too";

The CGI::Carp module provides versions of the warn and die Perl built-in functions, plus the Carp module's carp, cluck, confess, and croak functions which are more verbose and safer, too. They're more verbose because each message includes the date and time with the name of the program issuing the message, which helps when you're using a log file shared by a hundred different programs scribbling a thousand different messages on it at the same time.

The module is also kinder to web surfers, since premature death in a CGI script tends to cause inscrutable "Server 500" errors when the proper HTTP header doesn't get out to the server before your program pegs out, and this module makes sure that doesn't happen. The carpout function redirects all warnings and errors to the filehandle specified. The fatalsToBrowser directive sends a copy of such messages to the user's browser, too. These facilities ease debugging of problems in CGI scripts.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl, 2nd Edition

Mastering Perl, 2nd Edition

brian d foy
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata