in reply to Foreach & scalar ref: break of way that it is suposed to work!

for $foo (...) { ... }
is more or less equivalent to
{ local $foo; for $foo (...) { ... } }
or
{ my $foo; for $foo (...) { ... } }
depending on what $foo is (global or lexical).

This also means that

for my $foo (...) { ... }
is like
{ my $foo; for $foo (...) { ... } }

You can't local or my $foo{bar}.

Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).

Replies are listed 'Best First'.
Re2: Foreach & scalar ref: break of way that it is suposed to work!
by dragonchild (Archbishop) on Apr 08, 2003 at 22:53 UTC
    The entire issue is that you can local $foo{bar}.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.