in reply to finding the most popular in array
Yes you use a hash to count the occurences, sort on the values of this and print it.
my @ary = qw ( a a a a a b b b c c c c c c d d d d ); # use a hash to count occurrences my %pop; $pop{$_}++ for @ary; # sort hash on values, store sorted keys in array my @pop_sort = sort { $pop{$b} <=> $pop{$a} } keys %pop; # now print most popular print "Most popular $pop_sort[0]\n"; print "Least popular $pop_sort[-1]\n"; # show hash print "Key Count\n"; for my $key (@pop_sort) { print "$key => $pop{$key}\n"; }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|