Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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"; } }

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?
[marto]: in house as in Company network, not internet connected (power stations and the corporate HQs)
[Discipulus]: new Monsignor party! free beverages and pizza for all you monks! and a big thanks for the patience you deserved me during these years
[marto]: congrats Discipulus
[Discipulus]: only 4k points to sundial's level ..;=)
[Corion]: Yay Discipulus ;)
[Corion]: marto: Ah, so this will be training videos etc., cool!
[choroba]: Congratulations!
[marto]: Corion worse, some plant inspection, cameras moving thru pipes
[marto]: Discipulus yeah, just don't adopt his tactics :P
[marto]: the content for the most part is fairly dull, but if they go for it, they can use it for all sorts of video, they have no solution for this at the moment

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-07-28 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (425 votes). Check out past polls.