http://qs1969.pair.com?node_id=274958


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

Replies are listed 'Best First'.
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.