As I said, all the OP's examples use the global $_ but some Perl control structures localize that variable.
The same effect is illustrated here using global $::x...
use warnings; use strict; sub abc() { $::x = 'x'; } foreach $::x (1..2) { print "Before:$::x\n"; abc(); print "After:$::x\n"; } print "\$::x = $::x\n"; # warning for uninitialized value $x (global +scope) abc(); print "\$::x = $::x\n"; # prints $x = x
In reply to Re^3: What is the scope of $_?
by tobyink
in thread What is the scope of $_?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |