Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Adding a new element to Hash of Hashes

by hdb (Parson)
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
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 taking refuge in the Monastery: (14)
As of 2014-07-11 16:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (232 votes), past polls