Fellow monks, alow me to share a small revelation i had today.
open (FH, "$dir$file") or die "Can't open $dir$file: $!\n";
This is the normal Perl idom for opening a file, where $! is
"the text relating to the most recent system error value"
(quote: R. Swartz, "Learning Perl").
"The $! variable contains the error message returned by the
operating system"(quote L. Wall & al, "Programming Perl")
Now today, reading The Perl Cookbook, i came across this description
(in chap 7.20: Doing non-blocking I/O) :
use Errno;
$rv = syswrite(HANDLE, $buffer, length $buffer);
if (!defined($rv) && $!{EAGAIN} ...
"...We use the Errno module to test for the error EAGAIN.
Testing $!{EAGAIN} is the same as testing $! == EAGAIN."
I was temporarily warped by that last statement..., having used
$! in mostly the simplistic way of
"what just went bang".
So jumping The Camel i (re)discovered that there's :
* a
$! ($ERRNO scalar) yielding the last syscall error
(numeric) or correspondisg syserror text (string context).
* a
%! (%ERRORNO hash) defined in the std. Errno.pm module
(including possibly vendor specific error-values)
so that eg. $!{EAGAIN} will be true if the C errno var.
is currently set to the C #define value "EAGAIN" for the specific
platform.
As it's further explained in The Camel on Errno.pm:
"The module also makes the global %! variable magical using tie.
You can subscript into the %! hash using any valid errno
on your system, not just the POSIX ones, and its value is true
only if that's the current error."
So that explains why $!{EAGAIN} is the same as $!==EAGAIN,
even tho' it looked like magic...
it turned out it
was magic.
As probably most of you here would already know, but ever so often
Perl newbies like me are blinded by yet another flash of The Perl magic
and have to take a deep breath to bring down the pulse.
--Allan
===========================================================
As the eternal tranquility of Truth reveals itself to us, this very place is the Land of Lotuses
-- Hakuin Ekaku Zenji