in reply to RE: Populate $!
in thread Populate $!
The win here is that you are automagically correcting the return codes that you get from wait or close in case the error is being passed through from an external program.# Turns numerical return codes into text. See perlvar. sub get_system_error { my $code = shift; print "Code: $code\n"; unless ($code < 2**8) { $code >>= 8; } local $! = $code; return "$!"; }
And yes, this only makes sense if you are careful to preserve the return codes. However a lot of Perl code uses die, which tries to do that by default, so you have a shot. This applies if you are trying to figure out why something exited (note that the STDERR of that program is probably gone) so an educated guess for the problem is better than nothing. Not perfect, but pass *it* out in your log message, pointing out that this is a possible guess, and it will often be helpful. So the message would be something like this:
You don't lose any information, but also try to make it easy for a mere human to understand you...if (0 < $?) { my $sys_msg = get_system_error($?); die "'$cmd' failed. ret code $?. (Guess: '$sys_msg'?)"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
For Perl kids only!
by merlyn (Sage) on Oct 11, 2000 at 22:48 UTC | |
by tilly (Archbishop) on Oct 11, 2000 at 23:02 UTC |