The regular expression captured submatches ($1, $2, ...) are now more consistently unset if the match fails, instead of leaving false data lying around in them.
I believe this is referring to the fact that if a match has $1..$6 in one successful match, then only $1..$2 in the next match, that $3..$6 are more carefully set to undef now. I remember there being a patch to that effect.
If they were to change the other behavior, it would no longer be (usefully) upward compatible. This would have been a grave mistake, caught by someone (like me).
The reason the variables are not unset on failure is to permit:
if ($string = /... ( ... ) .../) { # overall match
if ($1 =~ /foo/) { # and $1 contains foo
...
} elsif ($1 =~ /bar/) { # nope? how about bar
...
}
}
If $1 reset on the failed match on the second line, then we couldn't
do the third match. This has been by design in Perl for over a decade now.
(And I just verified that 5.8.5 doesn't unset the variables, so it works as it always has.)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|