in reply to Re: How do closures and variable scope (my,our,local) interact in perl?
in thread How do closures and variable scope (my,our,local) interact in perl?
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.
As you have observed, apparently even without the use of my, the variable used for iteration in a foreach loop is implicitly localized. That is why it has a value inside the loop but not outside of it.
However, this is supposed to happen for both my and our variables and it appears to be happening for only for the our variables. Hmmm.
Best, beth
|
|---|