in reply to hashes with multiple values per key
use strict; use warnings; my %yahoo = (); while (<DATA>) { chomp; my ($value, $key) = split; $yahoo{$key} += $value; } foreach my $key (sort keys %yahoo) { print "$key: $yahoo{$key}\n"; } __DATA__ 12 AAAA 12 AAAA 15 BBBB 1222 CCCC 1 BBBB
Output:
AAAA: 24 BBBB: 16 CCCC: 1222
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hashes with multiple values per key
by convenientstore (Pilgrim) on Aug 07, 2007 at 00:30 UTC | |
by kyle (Abbot) on Aug 07, 2007 at 00:41 UTC | |
by GrandFather (Saint) on Aug 07, 2007 at 01:10 UTC |