Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Scope when initializing with references in a loop

by IraTarball (Monk)
on Dec 06, 2001 at 04:08 UTC ( #129816=note: print w/replies, xml ) Need Help??

in reply to Scope when initializing with references in a loop

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.,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://129816]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2019-05-20 10:55 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (128 votes). Check out past polls.