in reply to loop surprise
Hello morgon,
From perlsyn#Foreach-Loops (first paragraph):
The foreach loop iterates over a normal list value and sets the scalar 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 localization occurs only in a foreach loop.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: loop surprise
by morgon (Priest) on Apr 03, 2018 at 13:44 UTC | |
by golux (Chaplain) on Apr 03, 2018 at 15:10 UTC | |
by morgon (Priest) on Apr 03, 2018 at 18:00 UTC | |
by Your Mother (Archbishop) on Apr 03, 2018 at 18:21 UTC | |
by morgon (Priest) on Apr 03, 2018 at 20:50 UTC | |
| |
by LanX (Saint) on Apr 03, 2018 at 15:05 UTC |