Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: building array of hashes

by SuicideJunkie (Priest)
on Jun 28, 2013 at 19:33 UTC ( #1041322=note: print w/ replies, xml ) Need Help??


in reply to building array of hashes

FYI, you can edit your original post to clarify with an Edit: blah blah

Whenever you have multiple elements that are mysteriously identical, you've almost certainly got two references to the same thing in your set.

$AoH[0] >---\ \ -----> $hashref / $AoH[1] >---/

%hash is declared somewhere outside of the code you posted. Inside your loop, you push a reference to that hash onto your array. You then push more references to the SAME hash until the loop ends.

If you want different, independent hashes in each array element, then push @AoH, {Section=>$sec, Subsection=>$subsec, foo=>$bar}; to get references to a new anonymous hash each time.

Alternatively, you can do a deep copy on a template hash before tweaking it and putting a ref to the new copy into your array


Comment on Re: building array of hashes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2014-08-21 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (143 votes), past polls