in reply to Re^2: How to access outside variable
in thread How to access outside variable
In case the inner scope isn't just a plain block, but a subroutine, you can use PadWalker to get at the outer scope(s):
use PadWalker qw(peek_my); my $a=10; sub { my $a=11; my $my = peek_my(1); # one level up print ${$my->{'$a'}}; # 10 print $a; # 11 }->();
This isn't meant for everyday consumption, though... — better use unambiguous variable names.
|
|---|