in reply to finding the most popular in array
this goes through your array, ++ing the hash element with the key as the array item. It then sorts your hash by the values of those keys and prints them out, or as the last line show, assigns them to a new array in order. (replace @ary with your array name)my %pop; my @poporder; for(@ary) { $pop{$_}++; } for(sort { $pop{$a} <=> $pop{$b} } keys %pop) { print "$_: $pop{$_}\n"; } # can also do @poporder = sort { $pop{$a} <=> $pop{$b} } keys %pop;
- Ant
- Some of my best work - Fish Dinner
|
|---|