#!/usr/local/bin/perl
if (some condition) { exit; }
or, if you would like to print to STDOUT on the way out
#!/usr/local/bin/perl
if (some condition) { die "Failed the condition\n"; }
# you often use die to get out after failure to do something you
# needed to do, like open a file
#!/usr/local/bin/perl
open(IPF,"<input_File_name" or die "Failed to open input file, $!\n";
Note: because die prints to STDERR and not STDOUT, if you are using it in a cgi script whatever you print that way will usually NOT show up! My solution was to write a CgiError subroutine which takes an error message and prints an html page showing the error message and then exits. This achieves the same end, but allows you to display the error in the browser.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.