in reply to Re^2: What is the scope of $_?
in thread What is the scope of $_?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: What is the scope of $_?
by Lotus1 (Vicar) on Nov 27, 2012 at 13:49 UTC |