Welcome to the Monastery | |
PerlMonks |
Re^3: trapping system errorby pemungkah (Priest) |
on Aug 29, 2010 at 00:19 UTC ( [id://857871]=note: print w/replies, xml ) | Need Help?? |
TL;DR:
You want to say this: This runs your mkdir in a way that captures the output from mkdir's STDERR into $output (if the mkdir works, it doesn't print anything). If there was output from the invoked command, then we chomp the output to remove the trailing newline, and print it to STDOUT - for a CGI program, you must print stuff to STDOUT if you want to see it in the browser. Note that we printed a full report on the error, following the old journalistic standard of who, what, when, where, and why:
Note that I built the message, printed it with a newline, and then did a die with the message sans newline. This means that the message logged in the error log will have the line number and script name supplied automatically and the one shown in the browser won't. Why? Because the final user of the program does not care about scripts and line numbers, only results. The log gets the script name and line number because only developers read logs, not users, and the developers need to know this stuff, unlike the users.
In Section
Seekers of Perl Wisdom
|
|