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 |