http://www.perlmonks.org?node_id=173060


in reply to calculating the mode

Why are there so many lines here? AFAIKS all you need is a hash, a sort and an array.
$counts{$_}++ for @array_of_numbers; my @sorted_array = sort { $counts{$a} <=> $counts{$b} } keys %counts;

Basically, go through the array and tally the occurances of numbers within a hash.
Finally sort the keys of the hash using a sort on the number or occurances.

Or have I missed something?

Amended: thanks to Molt ;)

--

Brother Frankus.

¤