Maybe I'm misunderstanding what you're trying to say in your last paragraph, but localizing a variable *is* dynamic scoping. my is lexical scoping.
Note that if you use while things get hairier:
Givesmy $i=1; $i=~/(.)/; while ($i++<=4) { print "\$i = $i\n"; print "first: \$1 = $1\n"; $i=~/(3)/; print "second: \$1 = $1\n"; } print "after: \$1 = $1\n";
$i = 2 first: $1 = 1 second: $1 = 1 $i = 3 first: $1 = 1 second: $1 = 3 $i = 4 first: $1 = 3 second: $1 = 3 after: $1 = 1
Clearly there's some dynamic scoping going on, which is likely to save a lot of people from small mistakes. But in my example, it's all one block of code, so the inner result persists. I'm pretty sure it's easy to come up with lots of real-world examples of iterating with while and a capturing regex...so, caveat programmer.
In reply to Re^3: Problem with regexp or saved match variable.
by ssandv
in thread Problem with regexp or saved match variable.
by steve077
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |