in reply to Re: Difference b/w my and local var?
in thread Difference b/w my and local var?

local() variables, on the other hand, are visible to routines that are called from the block where they are declared.

Not quite. It doesn't make the variables visible outside the block.

sub foo { ??? how do you access the var ??? } { my %hash; local $hash{foo} = 123; foo(); }

It doesn't even create variables as your wording suggests. It's not that what you said is wrong, just unclear and/or misleading. (Compare to what I used earlier.)

Replies are listed 'Best First'.
Re^3: Difference b/w my and local var?
by Fletch (Bishop) on Mar 11, 2009 at 19:27 UTC

    Of course if you resort to minor evil there is a way to get at it . . . :)

    use PadWalker qw( peek_my ); sub foo { my $ebil = peek_my( 1 ); print $ebil->{'%hash'}->{foo}, "\n"; } { my %hash; local $hash{foo} = 123; foo(); }

    (Not that that's germane to the correct point you were making; just an interesting aside your ???s brought up :)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.