note
CountZero
Is this doing what you want?<c>use Modern::Perl;
use Data::Dump qw/dump/;
my %seen;
my %accounts;
my $g_total;
while (<DATA>) {
next if $seen{$_}++;
my ( $account_number, $amount ) = ( split /,/ )[ 2, 7 ];
@{ $accounts{$account_number} }[0] += $amount;
@{ $accounts{$account_number} }[1]++;
$g_total += $amount;
}
say dump( \%accounts );
say "Grand Total = $g_total";
__DATA__
Joe Smith,12345678,44552,02/11/2011,no email, MA,USA,900.00,updated
Joe Smith,12345678,44552,02/11/2011,no email, MA,USA,900.00,updated
Joe Smith,12345678,44552,02/11/2011,no email, MA,USA,900.00,updated
Cindy Abbot,122233678,01122,08/09/2012,test@tok.com, CA,EUR,-120.00,updated
Mary Lou,33456678,44552,01/11/2011,no email, MA,USA,400.00,updated
SMith Doo,12345678,44592,02/11/2012,test@test.com, MA,USA,100.00,updated
Mario Att,00056789,022345,03/10/2010,no email, MA,USA,40.00,outdated
Mario Att,00056789,022345,03/10/2010,no email, MA,USA,40.00,outdated
Mario Att,00056789,022345,03/10/2010,ok@ok.com, MA,USA,40.00,outdated
Maria Smither,12345678,00051,02/11/2011,no email, MA,USA,750.00,outdated
Dan Smither,12345678,00051,02/11/2011,no email, MA,USA,250.00,outdated
</c><p>Output:<c>{
"00051" => [1000, 2],
"01122" => [-120, 1],
"022345" => [80, 2],
"44552" => [1300, 2],
"44592" => [100, 1],
}
Grand Total = 2360</c><p>The hash <c>%accounts</c> hold the accountnumber as key and each value is a reference to an array containing the total for that account and the number of times the accountnumber was found in the data.<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-198160">
<p>CountZero</p><p><i>A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity."</i> - [http://www.canonical.org/~kragen/tao-of-programming.html|The Tao of Programming], 4.1 - Geoffrey James</p>My blog: [http://imperialdeltronics.wordpress.com|Imperial Deltronics]
</div></div>
993761
993761