Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

$! or &Errno or $!{}

by tadman (Prior)
on Mar 20, 2001 at 22:05 UTC ( #65765=perlquestion: print w/ replies, xml ) Need Help??
tadman has asked for the wisdom of the Perl Monks concerning the following question:

Inside of, there is some rather unruly looking Perl in the connect() routine. In particular $! is used as a hash, implying that there is something called %!, which in fact seems to exist (according to 'perl -w' anyway).      if ($timeout && $!{EINPROGRESS}) { # ...
It's bizarre enough that $! behaves differently in a string context versus a numeric one, but now it has some sort of hidden "hash" context?

Comment on $! or &Errno or $!{}
Download Code
Replies are listed 'Best First'.
Re: $! or &Errno or $!{}
by Albannach (Prior) on Mar 20, 2001 at 22:21 UTC
    Looked odd to me too but I found this clue in perldiag (apparently added in Perl 5.005):

    The first time the %! hash is used, perl automatically loads the module. The Errno module is expected to tie the %! hash to provide symbolic names for $! errno values.

    I'd like to be able to assign to an luser

Re: $! or &Errno or $!{}
by jlawrenc (Scribe) on Mar 21, 2001 at 01:49 UTC
    I was confused by this as well. My cause to delve into IO::Socket was a breakdown of my LWP modules.

    Go to your Perl source can check out:

    the directory ext/Errno

    This is where these strings are actually obtained and made into the module which in turn gives rise to %!.

    What is going on here is that at make time Errno_pm.PL actually checks the cpp output to get a list of headers to scan. This output comes from something along the lines of "cpp your cpp flags errno.c". "errno.c" has a single line "#include <errno.h> Then it will scan all of these header files for #defines. (check out /usr/lib/errno.h or /usr/lib/asm/errno.h if you have it). Taking these defines, it will write the code for "" which ultimately lives in "lib/perl5/5.6.0/<arch>/

    The values for %! are supplied via a tied hash from

    Why do I know this? Well because shipped with RedHat did not correctly report all of the headers to scan. When the IO::Socket went to test against $!{EINPROGRESS} it did not match. It was always giving me "Timeout" messages. :( After tracing this through I found the defective output from cpp and the rest is history.

    You need the updated cpp that RedHat supplies. This version (dated Dec 18, 2000) works correctly.


Re: $! or &Errno or $!{}
by chipmunk (Parson) on Mar 21, 2001 at 00:32 UTC
    "Hash context"?? $! and $!{EINPROGRESS} is no more bizarre than $var and $var{KEY}. Just like $var and %var, $! and %! are two separate variables.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://65765]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2015-12-01 15:17 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (13 votes), past polls