This C-style for:
1 =~ /1/; for (my $i = 3; $i =~ /[34]/; $i++) { print $&; } print $&;
says 341, not 344. Isn't it because of beyond-body, outer-implied-braceless scope, which is same as in similar while loop?
Or did you mean something else, by "per-pass" (is it same as "per-loop") scope? The confusing part is why $& in OP (but not localized $x in hv's code) preserves its value between iterations.
And further (maybe unrelated; sorry, have just seen it, can't un-see):
1 =~ /1/; for ((my $i = 3) =~ /./; $i =~ /[34]/; $i++) { print $&; } print $&;
says 343. Again, sorry if it's waste of time, these are (questionably) good in idle golf etc., seem not have bothered busy people in 30+ (?) years.
In reply to Re^2: Regexp vars localization in blocks
by Anonymous Monk
in thread Regexp vars localization in blocks
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |