<br><br><div class="gmail_quote">On Mon, Nov 21, 2011 at 1:00 PM, Mike Stok <span dir="ltr"><<a href="mailto:mike@stok.ca">mike@stok.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="word-wrap: break-word;"><div><div></div><div class="h5"><br><div><div>On 2011-11-21, at 12:54 PM, Antonio Sun wrote:</div><br><blockquote type="cite">I want the program exit code to reflect the fact whether the pattern has been found or not. . . <br>
</blockquote></div></div></div><div><br></div><div>You can do something like</div><div><br></div><div>@matches = $string =~ /.(.)./;</div><div><br></div><div>And then see if @matches has any elements.<br></div><div></div>
</div></blockquote><div><br><br>Thanks Mike. I'm following your advice and am now able to detect failed pattern matches. <br><br>Now there is a new problem. I found that I am not able to set the exit code.<br><br>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:<br>
<br>    $ret = @matches ? 0 : 1;<br>    $self->debug("toret: $ret", 1);<br>    exit $ret;<br><br>Executing the code with:<br><br>my-script; echo Ret:$?<br><br>yields:<br><br>toret: 1Ret:0<br><br>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. <br>
<br>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. <br>
<br>Thanks<br><br>Antonio<br></div></div>