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


in reply to Scope when initializing with references in a loop

BING
The light bulb just went on.

So in the loop I'm assigning an anonymous hash reference. If I change those lines to index to the actual element it behaves like I originally expected.

$array[$i]{val} = rand(time)%3; $array[$i]{one} = \$array[1]{val};
In the original code the anonymous hash is really a new hash, ofcourse, so it's a whole new chunk of data in the array element with a new memory location and everything. But the old data still had references to it from the first two elements of the array so it was not cleared, just no longer available from $array[1]{val}.

I appologize for wasting space here, I think I just needed to throw this out there to get my head working.

Thanks for your time,
Peter C.,