in reply to "for" surprise
The "foreach" loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn. If the variable is preceded with the keyword "my", then it is lexically scoped, and is therefore visible only within the loop. Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop. If the variable was previously declared with "my", it uses that variable instead of the global one, but it's still localized to the loop. This implicit localisation occurs *only* in a "foreach" loop.And I know we talk about it in the llama book.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: •Re: "for" surprise
by fletcher_the_dog (Friar) on Nov 21, 2003 at 20:03 UTC | |
by merlyn (Sage) on Nov 21, 2003 at 20:07 UTC | |
by Corion (Patriarch) on Nov 21, 2003 at 20:07 UTC | |
by fletcher_the_dog (Friar) on Nov 21, 2003 at 20:26 UTC | |
by etcshadow (Priest) on Nov 22, 2003 at 03:42 UTC | |
by Abigail-II (Bishop) on Nov 21, 2003 at 21:24 UTC |