[tpm] Reliable exit code

Antonio Sun antoniosun at lavabit.com
Mon Nov 21 17:08:23 PST 2011


On Mon, Nov 21, 2011 at 1:00 PM, Mike Stok <mike at stok.ca> wrote:

>
> On 2011-11-21, at 12:54 PM, Antonio Sun wrote:
>
> I want the program exit code to reflect the fact whether the pattern has
> been found or not. . .
>
>
> You can do something like
>
> @matches = $string =~ /.(.)./;
>
> And then see if @matches has any elements.
>


Thanks Mike. I'm following your advice and am now able to detect failed
pattern matches.

Now there is a new problem. I found that I am not able to set the exit code.

The whole program is written in OO fashion. The executed part is in a
*derived* class. The last several lines before my code terminates are:

    $ret = @matches ? 0 : 1;
    $self->debug("toret: $ret", 1);
    exit $ret;

Executing the code with:

my-script; echo Ret:$?

yields:

toret: 1Ret:0

We can clearly see that the value of '$ret' is 1, and is taken as the
script exit code; but what the exit code seen from the outside is actually
0.

exit is supposed to exit immediately with that value. I don't have any
defined "END" routines, nor any traps, or explicitly defined class
destructors. Why my exit didn't exit with the given exit code? My perl is
5.10.1-12ubuntu2.

Thanks

Antonio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20111121/d85ac7c6/attachment.html>


More information about the toronto-pm mailing list