Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: building array of hashes

by Eily (Hermit)
on Jun 28, 2013 at 19:35 UTC ( #1041324=note: print w/ replies, xml ) Need Help??


in reply to building array of hashes

Since you do not declare your hash inside of your for loop, it is always the same one you push into the array. You do not have a new one with new values, you just replace them.

There are two things you can do. Either declare your hash lexically (with my) inside the for loop, and you'll have a brand new one each time, or youcan make a new one to push into AOH. With push @AOH, { %hash }; # copy of %hash here

Both are possible, but it would probably be better to have your my %hash in the for loop, because you can be sure to have only new values, not ones that you somehow didn't delete or change.


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://1041324]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2014-09-19 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (147 votes), past polls