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;
In reply to Populate $! by tilly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |