On Mon, May 17, 2010 at 11:54:32AM -0600, Kelly Jones wrote: > I did this in tcsh: > > > perl -le 'exit(2); sub END {system("date");}' ; echo $status > Mon May 17 11:09:43 MDT 2010 > 0 > > In other words, the return value of the date command in an END subroutine > overrides my desired exit value. > > How do I fix this? I want to tell Perl: if I explicitly do exit($foo), I > want the script to exit with status $foo?
>From perldoc perlmod: Inside an "END" code block, $? contains the value that the program is going to pass to "exit()". You can modify $? to change the exit value of the program. Beware of changing $? by accident (e.g. by running something via "system"). >From perldoc -f local: A local modifies the listed variables to be local to the enclosing block, file, or eval. So: $ perl -le 'exit(2); sub END { local $?; system("date");}' Alternatively, if you want to exit without running the END block(s): $ perl -MPOSIX -le '_exit(2); sub END {system("date")}' -- Paul Johnson - p...@pjcj.net http://www.pjcj.net -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/