At work I learned about a tool called perror, that showed the literal string corresponding to a numeric UNIX error. So if you get a message from a program that says "errno 13", you can run perror to easily translate that into "Permission denied". When I went to install it at home, I found out that it's in Debian package mysql-server (!). So I made my own version:

foreach (grep /^\d+$/, @ARGV) { $! = $_; print "$_: $!"; }

Which can be turned into a oneliner:

$ perl -le'print "$_: ", $! = $_ foreach grep /^\d+$/, @ARGV' 13 20 +## It even respects your locale settings 13: Permiso denegado 20: No es un directorio

--
David Serrano

Replies are listed 'Best First'.
Re: perror.pl
by samtregar (Abbot) on Jul 05, 2006 at 17:20 UTC
    Why the grep? I'd write that:

       perl -le 'print "$_: " . ($! = $_) for @ARGV' 13 20

    -sam

      My actual program has some useless lines before the ones I posted, along the lines of use warnings; use strict; (yes, I use them always). Under that conditions:

      $ perl -Mstrict -wle 'print "$_: " . ($! = $_) for @ARGV' 13 20 invali +d 13: Permiso denegado 20: No es un directorio Argument "invalid" isn't numeric in scalar assignment at -e line 1. invalid:

      In fact, even with the grep, a bug remains where the parameter 0 is supplied. I didn't bother fixing it.

      --
      David Serrano