#!/usr/bin/perl -w use strict; use Data::Dumper; my @data = ( qw/ 2 3 3 3 5 7 8 12 32 44 55 12 3 23 43 33 1 4 25 43 42 1 4 5 3 3 3 /); my $mode = mode( { 'NUMBERS' => \@data } ); # I quote hash keys so I don't # mistake them for constants # and use them as barewords. print "Mode : $mode\n"; sub mode { my %count = (); my %opt = %{ shift @_ }; for ( @{ $opt{'NUMBERS'} } ) { # no need to sort the array here $count{ $_ }++; } my @key = sort{ $count{$b} <=> $count{$a} } keys %count; return $key[0]; } __END__