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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.