in reply to why need my in a foreach loop?
When using strict perl requires to declare even the loop variable of a foreach loop.
It can use package variables, for starters.
our $foo; sub f { print("$foo\n"); } for $foo (qw( a b c )) { f(); # Prints a, b and c. }
Foreach loops existed long before "my".
Why is this code not allowed?
It generates an error for all instances of $word since you never declared it and you asked to make such things errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: why need my in a foreach loop?
by 7stud (Deacon) on Nov 28, 2010 at 19:59 UTC | |
by ikegami (Patriarch) on Nov 28, 2010 at 23:23 UTC | |
by 7stud (Deacon) on Dec 02, 2010 at 03:46 UTC | |
by ikegami (Patriarch) on Dec 02, 2010 at 16:38 UTC |