7.10. A Note About die()
In Chapter 4, we learned that when things go disastrously wrong in a Perl program, the situation should be dealt with by terminating the program with the die() function. This function prints a message to the standard error output, cleans up nicely, and exits the program with a nonzero exit status.
In CGI programs, if the die() function is executed, we may think that the string passed to the function will end up in the browswer. However, standard error output is not sent on to the client that requested the CGI program; instead, it is written to the error log file (here, /var/www/logs/error_log). For instance, if the CGI program test.cgi contains this line:
open FH, ´/var/www/data/mydata.dat´ or die "File not opened: ...
Get Open Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.