Perl doesn&#39;t reset these variables if the regex doesn&#39;t match which is why you always have to test whether the regex was true before  using $1, $2, etc.  From <a href="http://perldoc.perl.org/perlre.html">http://perldoc.perl.org/perlre.html</a>:<br>
<br><div><span class="Apple-style-span" style="font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, Geneva, sans-serif; font-size: 13px; color: rgb(81, 81, 81); "><b>NOTE</b>: Failed matches in Perl do not reset the match variables, which makes it easier to write code that tests for a series of more specific cases and remembers the best match.</span></div>
<div><font class="Apple-style-span" color="#515151" face="&#39;Helvetica Neue&#39;, Arial, Helvetica, Geneva, sans-serif"><br></font></div><div><font class="Apple-style-span" color="#515151" face="&#39;Helvetica Neue&#39;, Arial, Helvetica, Geneva, sans-serif"><font class="Apple-style-span" color="#000000">In your case the range operator as a whole remains true even while the LHS is false which is why you have to rewrite it the way you did.</font></font></div>
<div><font class="Apple-style-span" color="#515151" face="&#39;Helvetica Neue&#39;, Arial, Helvetica, Geneva, sans-serif"><font class="Apple-style-span" color="#000000"><br></font></font></div><div><font class="Apple-style-span" color="#515151" face="&#39;Helvetica Neue&#39;, Arial, Helvetica, Geneva, sans-serif"><font class="Apple-style-span" color="#000000">Garth<br>
</font></font><br><div class="gmail_quote">2010/9/16 yary <span dir="ltr">&lt;<a href="http://not.com">not.com</a>@<a href="http://gmail.com">gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<br><br>I&#39;m going through logs seeing if a change improved a particular SQL statements execution time. The part I&#39;m interested looks like this:<br><br>  insert into foo..bar_440_5678_D<br>  select<br>        a.pd,<br>


        <a href="http://a.tg" target="_blank">a.tg</a>,<br>  ....<br>  Elapsed time: 0m27.485s<br><br>I&#39;m interested in the &quot;5678&quot; and the time it took. Seems like the flip-flip &quot;..&quot; is perfect for a quick hack to extract that info:<br>


<br>perl -ne &#39;if(/insert into foo\.\.bar_440_(\d+)/../time: (.+)/&amp;&amp;$1){print &quot;$1\n&quot;}&#39; SQL.log<br><br>The thing is, it prints &quot;5678&quot; many times, until it gets to the &quot;Elapsed time&quot; portion. I would expect that the lines between the start and the end, which don&#39;t match, to clear $1.<br>


<br>I ended up with a longer one-liner to extract the info I was looking for-<br><br>perl -ne &#39;if(((/insert into foo\.\.bar_440_(\d+)/ and $a=$1)..(/time: (.+)/ and $b=$1))&amp;&amp;$b){print &quot;$a took $b\n&quot;;$b=0}&#39; SQL.log<br>


<br>Now I&#39;m curious why I couldn&#39;t rely on $1 being undefined for the intermediate lines. Anyone have a good explanation?<br><font color="#888888"><br>-y<br><br><br>
</font><br>_______________________________________________<br>
SanFrancisco-pm mailing list<br>
<a href="mailto:SanFrancisco-pm@pm.org">SanFrancisco-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/sanfrancisco-pm" target="_blank">http://mail.pm.org/mailman/listinfo/sanfrancisco-pm</a><br>
<br></blockquote></div><br></div>