[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Autom4te::General
From: |
Alexandre Duret-Lutz |
Subject: |
Re: Autom4te::General |
Date: |
Mon, 02 Jun 2003 22:15:32 +0200 |
User-agent: |
Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3 (gnu/linux) |
>>> "Russ" == Russ Allbery <address@hidden> writes:
[...]
Russ> I'm sorry, I don't understand. If you end the die
Russ> message with a newline, it doesn't do anything with $! at
Russ> all.
Sorry, I'm talking about how `die' computes the exit status of
your program, not what the diagnostic contains.
die LIST
Outside an "eval", prints the value of LIST to "STDERR" and
exits with the current value of $! (errno). If $! is 0, exits
with the value of "($? >> 8)" (backtick `command` status). If
"($? >> 8)" is 0, exits with 255.
% cat x.pl
$! = 120;
die "hello\n";
% perl x.pl
hello
% echo $?
120
Russ> The standard Perl programming idiom looks like this:
Russ> open (FILE, $file) or die "cannot open $file: $!\n";
Exactly. My feeling is that this is the only sane use of die.
Calling any function between the error and die would be wrong as it
could trash the value of $!. Calling die in the middle of nowhere
to diagnose some logic error, as in (from autoscan.in)
die "$me: too many arguments
Try `$me --help' for more information.\n"
if @ARGV > 1;
is terrible, as it might actually return with a random exit
status.
The ugly hacks I've installed in Autoconf's Generic.pm recently
just work around these die usages. IMHO, the real fix is to stop
using `die' this way. `print STDERR' + `exit' is all we need.
[...]
--
Alexandre Duret-Lutz
Re: Autom4te::General, Akim Demaille, 2003/06/02