in reply to Quick way to find the letter with the most occurences in a string

Untested:
use List::Util 'reduce'; use 5.010; my %hash; $hash{$_}++ for split //, $my_string; say "Most frequent: ", reduce {$hash{$a} > $hash{$b} ? $a : $b} keys % +hash;
  • Comment on Re: Quick way to find the letter with the most occurences in a string
  • Download Code

Replies are listed 'Best First'.
Re^2: Quick way to find the letter with the most occurences in a string
by choroba (Cardinal) on May 19, 2010 at 16:44 UTC
    If there are several characters with most occurences, this code will report just one of them.
      this code will report just one of them
      Indeed. As specified. Notice the title: ...find the letter.... It did not say ...find the letters....
        Shouldn't it be a letter then? :)