# this sets $! and $^E unlink 'asdfasdfewtwertwevbncvbnmarewrawer'; # This wipes them both out. # Note that test.pl contains only "1;", and $@ is undef afterwards. eval {require "test.pl"}; print "\$\@: $@\n" if $@; # If I comment the eval line out, this prints: # error?: last system error: No such file or directory # (error number: 2) (extended error info: The system # cannot find the file specified # Otherwise it just prints: # error? print "error?: ", &CheckLastSystemError(), "\n"; # Here's my sub. Feel free to add suggestions for it also if you have any. sub CheckLastSystemError { my @message; # check the string value push @message, "$!" if $!; # we could check $^E here, too... # check the number value my $numericTest = 0 + $!; # force numeric context push @message, "(error number: $numericTest)" if $numericTest; # $^E is sometimes just the same as $! push @message, "(extended error info: $^E" if ($^E && $^E ne $!); if (scalar @message) { # combine @message into a string and return it return "last system error: @message"; } else { return undef; } }