|Perl Monk, Perl Meditation|
Regex Capturing: Is this a bug or a feature?by shotgunefx (Parson)
|on Sep 28, 2002 at 14:35 UTC||Need Help??|
shotgunefx has asked for the
wisdom of the Perl Monks concerning the following question:
After many hours of trying to trace down an anomoly in some test code, I ran into what appears to be a bug in regex caputring.
In perlre it states "The numbered variables ($1, $2, $3, etc.) and the related punctuation set ($+, $&, $`, $', and $^N) are all dynamically scoped until the end of the enclosing block or until the next successful match, whichever comes first. "
I've always taken this to mean they are "local" scoped to a block just as if you has said local($1), apparently this is not the case. Or at least not the case on my build of Perl v5.6.1
In the example below, after the first match, $1 and $2 are still populated every iteration after. Shouldn't they be reset?
"To be civilized is to deny one's nature."