in reply to Silly array-ish question.
Whenever I see a "sum this if that matches" type problem, I always think hash.
Given your 2-d array above, how about:
my %sums; for( my $i = 0; $i < $lines; ++$i ) { $sums{$data[$i][1]} += $data[$i][3]; }
The %sums hash now contains the sums keyed by the day (if I'm understanding what field 1 is).
Personally, I would tend to write this much more compactly, but this should work and is easier to understand.
Update: fixed stupid typoes. (Thanks JadeNB).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Silly array-ish question.
by gone2015 (Deacon) on Oct 23, 2008 at 16:53 UTC | |
|
Re^2: Silly array-ish question.
by gwadej (Chaplain) on Oct 23, 2008 at 18:28 UTC |