in reply to Re^2: You *Can* Catch errors in closing lexical filehandles
in thread Catching errors in closing lexical filehandles
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 $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.)if ($string = /... ( ... ) .../) { # overall match if ($1 =~ /foo/) { # and $1 contains foo ... } elsif ($1 =~ /bar/) { # nope? how about bar ... } }
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: You *Can* Catch errors in closing lexical filehandles
by ihb (Deacon) on Sep 27, 2004 at 23:09 UTC |