http://www.perlmonks.org?node_id=129810


in reply to Re: Scope when initializing with references in a loop
in thread Scope when initializing with references in a loop

*why* one wd do this)
It might be hard to see with this example, but the actual code has 'nodes' defined, each with references to it's "neighbors". The reference seemed clean because I could get at the values I want without having to figure out what the indices are for all of my neighbors. For this array it may seem trivial, but imagine an array of n dimensions.

the snag I see is that the first couple of times round the loop $array[1] is undefined.
This doesn't seem to matter. I was carefull to post the code in a way that the "d/l code" link would give you the actual code I'm referring to. If you do, and you run it, the array values all get initialized in the outer most scope by first. Still, in the loop, I seem to get a reference to some new value.

Ira,