in reply to Running Total Array or Hash
each record has the name of the clientThis sounds like indexing results by strings, which says "use a hash" to me. Algorithmically, that might look something like:
#!/usr/bin/perl -w use strict; my %sum; while (<DATA>) { my ($name, $value) = split; $sum{$name} += $value; } for my $key (sort keys %sum) { print "$key: $sum{$key}\n"; } __DATA__ a 1 b 5 a 3 b 7 c 9 a 2
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Running Total Array or Hash
by DeWebDude (Initiate) on Mar 10, 2014 at 19:49 UTC | |
by DeWebDude (Initiate) on Mar 10, 2014 at 20:04 UTC | |
by VincentK (Beadle) on Mar 10, 2014 at 20:21 UTC | |
by Laurent_R (Canon) on Mar 10, 2014 at 21:41 UTC | |
by kcott (Archbishop) on Mar 11, 2014 at 07:09 UTC |