Ok in that case, which ones are considered to be system calls?
Good question, I thought there was a full list in the perldocs, but I can't find it - most of it is documented in perlfunc, but print() also sets $! on error (and returns false), which isn't documented there, so there might be omissions.
In general, errors from child processes in system() and `` are set in $? (though they set $! if the exec() fails), eval() errors are set in $@ and system errors that are not handled otherwise in the interpreter (not promoted to exceptions or worked around) set their errors in $! - these include file and pipe errors from print(), open(), read(), close() etc. All these functions return some value to indicate success/failure, and you should only read $! on failure.
If you want to be sure, "Programming Perl 3rd edition" (the Camel book) has a list of all built-in functions and and also notes which ones set $!.
Also, you might want to take a look at the standard (since perl 5.6) Fatal module. With it you can force an exception on functions that return false on error if you don't explicitly test for them (sadly, it doesn't work with system() and other functions that return true on error):
from the docs:
use Fatal qw/:void open close/;
# properly checked, so no exception raised on error
if(open(FH, "< /bogotic") {
warn "bogo file, dude: $!";
}
# not checked, so error raises an exception
close FH;
update: just to answer your other question: running out of memory in the interpreter will throw an exception which is untrappable by default (so your code should die on the line causing the exception). In theory, it's possible to catch this exception, but your code probably isn't trying to. See the $^M entry in perlvar.
|