Its magic is documented in perlvar, but basically, what $! contains is the "errno" C runtime library value for the last system-related (I don't want to say "system" call, since I don't only mean that function) call that failed.
You CAN assign to errno, but only integer values, which you can find in your system's documentation, or in the errno.h C header file for your platform (if it's unix-ish, check /usr/include/errno.h).
The "string" value of $! is whatever string your system decides goes with a given integer, so none of them are going to be "these were not digits". Your best bets in that case might be 22 (EINVAL "Invalid argument") or 33 (EDOM, "Domain error in Math Function). At least, those are valid for AIX, Solaris, and Linux, and probably for other Unices, as well as for Windows. (A quick search finds that EDOM is actually required to exist per the C standard - of course, it's likely that nothing says it has to be 33 on your platform...)
To test, you can do:
perl -e'foreach(1..33){$!=$_; print "$_: $!\n"}'
In reply to Re: How do I return false and set an error in special variable $!
by RMGir
in thread How do I return false and set an error in special variable $!
by leocharre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |