Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: List standard Unix error codes (less output, more code)

by tye (Cardinal)
on Jul 16, 2003 at 18:01 UTC ( #274958=note: print w/ replies, xml ) Need Help??


in reply to List standard Unix error codes

I don't like to see "Unknown error" dozens of times. So I prefer the longer:

# Win32: perl -e "print grep !/unknown error/i, map $_.qq'\t'.($!=$_).$/, 0..12 +7" # Other: perl -e 'print grep !/unknown error/i, map $_."\t".($!=$_).$/, 0..127'
Or you can get fancy like:
# Win32: perl -MErrno -e "my %e= map { Errno->$_()=>$_ } keys(%!); print grep ! +/unknown error/i, map sprintf('%4d %-12s %s'.$/,$_,$e{$_},$!=$_), 0.. +127" # Other: perl -MErrno -e 'my %e= map { Errno->$_()=>$_ } keys(%!); print grep ! +/unknown error/i, map sprintf("%4d %-12s %s".$/,$_,$e{$_},$!=$_), 0.. +127'
which produces output like:
0 1 EPERM Operation not permitted 2 ENOENT No such file or directory 3 ESRCH No such process 4 EINTR Interrupted function call
Enjoy. (:

Update: Change the /unknown error/i bit to match your platform. I expected Perl to just use the standard strerror() but it appears that this code is split up much more than that and unknown error codes are handled rather differently on different platforms (the "Unknown error" is in Win32-specific source code for Perl).

                - tye


Comment on Re: List standard Unix error codes (less output, more code)
Select or Download Code
Re**2: List standard Unix error codes (less output, more code)
by belg4mit (Prior) on Jul 16, 2003 at 20:14 UTC
    Heheh, solaris nicely forgoes the Unkown Error en lieu of Error xxx.

    --
    I'm not belgian but I play one on TV.

Re^2: List standard Unix error codes (less output, more code)
by gordoste (Initiate) on Jan 05, 2006 at 05:19 UTC
    If you want to look up a specific error code, you can't beat:
    perl -lpe '$_=$!=$_'

    Sufficiently advanced Perl is indistinguishable from garbage.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://274958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-07-11 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls