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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.