in reply to Re^3: Creating an array of hash references
in thread Creating an array of hash references

Nope - each time through the while loop, you're getting a new %event - each one gets its own address allocated. If the "my" were outside of the while loop, you'd be right. As it is, all your change accomplishes is to copy the hash around an extra time (into an anonymous reference) more than is required.

(If there is no reference to the %event, the perl VM may optimise it away and just refill the same one, but since the OP is taking a reference to it which lasts through the end of the loop, perl cannot make that optimisation, and allocates a new one.)

  • Comment on Re^4: Creating an array of hash references