Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
# heres a snippet # @items contains all the thing i want to calculate frequency of. print "Items: @items\n"; # determine the frequency of each item. Sort them in ascending order. my %freq; my $count; foreach $pair (@items) { $freq{$pair}++; } # next foreach not working - want to print no of each individual item foreach $pair (@items) { ++$count; } my @array = sort { $freq{$b} <=> $freq{$a} } keys %freq +; print "Sorted:@array\n"; print "Count:$count\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: calculating frequency of item in an array
by davorg (Chancellor) on Feb 27, 2003 at 10:31 UTC |