Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; my %seen=(); my %count; my @flds; my @g_total; while (<DATA>){ chomp; # get rid of dup lines next if $seen{$_}++; @flds=split /,/; # look up accounts in array position 2 and count its accuracies and a +dd amounts from position arrays 7 fro each one. if (!$seen{$flds[2]}++){ if($flds[2] eq $flds[2]){ $flds[7]+=$flds[7]; print "From Account# $flds[2] - Total = $flds[7]\n"; } push @g_total, $flds[7]+=$flds[7]; } print "\nGrand Total = $g_total[0]\n"; __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,up +dated 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,updat +ed 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,outdat +ed Dan Smither,12345678,00051,02/11/2011,no email, MA,USA,250.00,outdated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting how many times item is occurring and adding the total from array help!
by CountZero (Bishop) on Sep 14, 2012 at 19:34 UTC | |
by Anonymous Monk on Sep 14, 2012 at 19:42 UTC | |
by CountZero (Bishop) on Sep 14, 2012 at 20:34 UTC | |
by Anonymous Monk on Sep 15, 2012 at 12:07 UTC | |
|
Re: Counting how many times item is occurring and adding the total from array help!
by toolic (Bishop) on Sep 14, 2012 at 18:19 UTC | |
by Anonymous Monk on Sep 14, 2012 at 19:23 UTC |