in reply to Perl syntax question
Check out perldoc perlvar and you'll get some explanations about Perl's "special variables." Here is a quick sniglet from that doco:
The variables $@, $!, $^E, and $? contain information about different
types of error conditions that may appear during execution of a Perl
program. The variables are shown ordered by the "distance" between the
subsystem which reported the error and the Perl process. They
correspond to errors detected by the Perl interpreter, C library,
operating system, or an external program, respectively.
Digging deeper into your question, here is what the doco says about $!:
$! If used numerically, yields the current value of the C "errno"
variable, or in other words, if a system or library call fails,
it sets this variable. This means that the value of $! is
meaningful only immediately after a failure:
if (open my $fh, "<", $filename) {
# Here $! is meaningless.
...
}
else {
# ONLY here is $! meaningful.
...
# Already here $! might be meaningless.
}
# Since here we might have either success or failure,
# here $! is meaningless.
The meaningless stands for anything: zero, non-zero, "undef". A
successful system or library call does not set the variable to
zero.
If used as a string, yields the corresponding system error
string. You can assign a number to $! to set errno if, for
instance, you want "$!" to return the string for error n, or
you want to set the exit value for the "die()" operator.
Mnemonic: What just went bang?
and what it says about %!
%! Each element of "%!" has a true value only if $! is set to that
value. For example, $!{ENOENT} is true if and only if the
current value of $! is "ENOENT"; that is, if the most recent
error was "No such file or directory" (or its moral equivalent:
not all operating systems give that exact error, and certainly
not all languages). To check if a particular key is meaningful
on your system, use "exists $!{the_key}"; for a list of legal
keys, use "keys %!". See Errno for more information, and also
see "$!".
This variable was added in Perl 5.005.
which is what the syntax your cite is working with.
|
|---|