in reply to Sum fields in Array
Probably I'm misunderstanding something about your question, but summing up is simply done like this:
... my $sumcredits; while (my $pimrpt = <PM>) { ... $sumcredits+= $credits; ... } print "The sum of credits is $sumcredits\n";
If you need to add credits seperate for each company, change that to
... my %sumcredits; while (my $pimrpt = <PM>) { ... $sumcredits{$company}+= $credits; ... } foreach my $comp (keys %sumcredits) { print "The sum of credits for $comp is $sumcredits{$comp}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sum fields in Array
by drodinthe559 (Monk) on Feb 04, 2010 at 20:56 UTC | |
by drodinthe559 (Monk) on Feb 04, 2010 at 21:01 UTC | |
by jethro (Monsignor) on Feb 04, 2010 at 21:24 UTC |