The secret involves some deep magic of $! that is documented in perlvar. It is different when being treated as a string and a number. You can assign the numerical return code, and when used as a string it will have the text of the message. (If the return is being used as a string, there is no need to coerce it like I did. But enough magic is going on that I *prefer* doing that.)
# Turns numerical return codes into text. See perlvar. sub get_system_error { local $! = shift; return "$!"; } print "$_: ", get_system_error($_), "\n" foreach 1..50;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Populate $!
by Fastolfe (Vicar) on Oct 11, 2000 at 21:50 UTC | |
by tilly (Archbishop) on Oct 11, 2000 at 22:39 UTC | |
by merlyn (Sage) on Oct 11, 2000 at 22:48 UTC | |
by tilly (Archbishop) on Oct 11, 2000 at 23:02 UTC | |
|
RE: Populate $!
by merlyn (Sage) on Oct 11, 2000 at 22:27 UTC |