I

On May 17, 2010, at 11:21 AM, John W. Krahn wrote:

> John W. Krahn wrote:
>> 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?
>> This is probably what you want:
>> $ perl -le' END { system "date"; $? = 2 } ' ; echo $?
>> Mon May 17 11:01:37 PDT 2010
>> 2
> 
> Or don't use something that sets $? in the END block:
> 
> $ perl -le' exit 2; END { print scalar localtime } ' ; echo $?
> 

Is it possible to set $?, as in
{ 
my $exit = $?;
system ("do something");
$? = $exit;
}

or ...
{
my $exit = $?
system ("do something");
return $exit;
}

I'm having a bit of trouble with a DESTROY method on a object that needs to 
clean up external persistent data when an object is no longer referenced.  I 
inherited the code, and the program is not cleaning up objects before exiting.  
The DESTROY method does the cleanup on exit, and changes the return code.  What 
would be the right way to change that DESTROY method?  

thanks,
--Marilyn


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to