Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Adding a new element to Hash of Hashes

by hdb (Prior)
on Apr 09, 2013 at 13:05 UTC ( #1027728=note: print w/ replies, xml ) Need Help??


in reply to Adding a new element to Hash of Hashes

Your first hash assignment stores a value $_->{'total'} in the hash and the second line (that doesn't work) overwrites it. You need to add another level to your hash:

my %hash; $hash{$_->{'type'}}{$_->{'name'}}{'total'} = $_->{'total'} for @$array +; $hash{$_->{'type'}}{$_->{'name'}}{'id'} = $_->{'id'} for @$array; print "Results:\n"; for my $k1 (sort keys %hash) { print " $k1:\n"; for my $k2 (sort keys %{$hash{$k1}}) { print " id - $hash{$k1}{$k2}{'id'} - $k2 - $hash{$k1}{$ +k2}{'total'}\n"; } }


Comment on Re: Adding a new element to Hash of Hashes
Download Code
Replies are listed 'Best First'.
Re^2: Adding a new element to Hash of Hashes
by Anonymous Monk on Apr 09, 2013 at 13:21 UTC
    Thanks a lot!! It solved!!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (19)
As of 2015-07-28 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls