in reply to Re: wisdom needed
in thread wisdom needed: sorting an array
The principal of counting frequency is based on this type of code:
my @array = (1,1,1,2,3,3,4,4,4,4); my %count; $count{$_}++ for @array; my @ordered = sort {$count{$b} <=> $count{$a}} keys %count; print map {"$_\n"} @ordered;
The hash stores the count in the value and the item in the key. The keys are then sorted by comparing the values with eachother, with respect to the keys.
--
Steve Marvell
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: wisdom needed
by Anonymous Monk on Jun 06, 2002 at 14:15 UTC |