I'm not sure, but it seems otherwise to me. Consider the following example:
my $_ = '1'; /(.)/; print "before: \$1 = $1\n"; for (2..4) { print "\$_ = $_\n"; print "first: \$1 = $1\n"; /(3)/; print "second: \$1 = $1\n"; } continue {} print "after: \$1 = $1\n";
Which produces
before: $1 = 1 $_ = 2 first: $1 = 1 second: $1 = 1 $_ = 3 first: $1 = 1 second: $1 = 3 $_ = 4 first: $1 = 1 second: $1 = 1 after: $1 = 1
At least it is not the case that once a capture variable is set it can't go away by going out of scope. Not only does $1 of the inner scope go away after the loop is completed, but the previous value of the outer scope's $1 remains, unaltered by $1 having been set in the inner scope. And the $1 of the inner scope doesn't even persist from one iteration of the loop to the next. While this effect could be achieved by localization of a global variable, perlre says explicitly that the numbered match variables are dynamically scoped. And my understanding of dynamically scoped is that they are lexical variables, not localized global variables. Of course, I could be was wrong and confused dynamic and lexical scoping. , as could the documentation. I haven't looked at the implementation.
In reply to Re^2: Problem with regexp or saved match variable.
by ig
in thread Problem with regexp or saved match variable.
by steve077
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |