Skip to Main Content
Perl for Web Site Management
book

Perl for Web Site Management

by John Callender
October 2001
Beginner content levelBeginner
528 pages
15h 20m
English
O'Reilly Media, Inc.
Content preview from Perl for Web Site Management

die Statements

Oh, and that or die... thing. It’s a really, really good idea to stick an or die... statement like this in your Perl script every time the script is trying to open a filehandle or execute an external command of some sort. You should do this because these sorts of actions represent weak links in your script, where something can easily go wrong even though the script itself is functioning properly. Let’s say you get your script working and everything’s going great, but then someone comes along and moves the sendmail program on your Unix server, such that Perl can’t find it when it tries to open this pipe. Without an or die... statement, Perl will try to open the pipe, fail, and continue on as if nothing had happened. You, and the users of your CGI scripts, will never know there’s something wrong—except that you won’t be getting any emailed form submissions.

With the or die... statement there, however, the script will try to open the pipe, and when it fails the script will execute whatever comes after the or, which in this case means the die statement. The die statement makes the script stop dead in its tracks and print an error message. That message is printed to a special place called standard error , which actually means it prints to your screen in the case of scripts you run from the command line, or to the web server’s error log in the case of a CGI script. The error message that gets printed there is whatever comes after the die statement, so by making it a ...

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

Web Client Programming with Perl

Web Client Programming with Perl

Clinton Wong
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

Ken Williams, Dave Rolsky

Publisher Resources

ISBN: 1565926471Catalog PageErrata