http://www.perlmonks.org?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