Possible Duplicate:
How can I output unique, count and sum using perl
How can I get unique, count and sum values in perl? My code is as follows:
while (<$input>) {
chomp;
my($f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$f10,$f11,$f12,$f13,$f14,$f15,$f16,$f17,$f18,$f19,$f20,$f21,$f22,$f23,$f24,$f25) = split(/\|/);
$f24 = " " if !defined($f24);
push @ff4, qw($f4); # VEN 10/19/11
push @fff4, $f4, $f16, $f7; # VEN 10/28/11
..... ....... ...... ........ ......
..... ....... ...... ....... .......
my %count;
map { $count{$_} ++ } @array;
my@count = map { "$_ ==========> ${count{$_}}\n"} sort keys (%count);
#print $output2 sprintf("@count\n");
my %h;
my @el;
while (<@array>)
{
$h{$el[0]}{count}++;
$h{ $el[0]}{sum} += $el[2];
}
print $output2 %h;
I am getting output like this
08/2009 ====> 2030
08/2010 ====> 2300
09/2010 =====> 1500
But I have to get it like this:
08/2009 ====> 2
08/2010 ====> 3
09/2010 =====> 5
I am using Perl on Solaris