convenientstore has asked for the wisdom of the Perl Monks concerning the following question:
and I am trying to run below so that I can gather everything12 AAAA 12 AAAA 15 BBBB 1222 CCCC 1 BBBB
use strict; my $value; my $key; my $sum = 0; my %yahoo = (); while (<>) { ($value,$key) = split; # print "$key, $value\n"; # $sum += $value; # print "\$sum is $sum\n"; push (@{$yahoo{$key}}, ($sum += $value)); } foreach $key (sort keys %yahoo) { print "$key: @{$yahoo{$key}}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hashes with multiple values per key
by kyle (Abbot) on Aug 06, 2007 at 22:54 UTC | |
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 | |
|
Re: hashes with multiple values per key
by GrandFather (Saint) on Aug 06, 2007 at 23:03 UTC |