zeroclickinfo-goodies/lib/DDG/Goodie/Frequency.pm

39 lines
556 B
Perl
Raw Normal View History

2012-05-06 08:13:52 -07:00
package DDG::Goodie::Frequency;
2012-05-07 18:38:06 -07:00
# ABSTRACT: Displays frequency of alphabet character (a-z)
2012-05-06 08:13:52 -07:00
use DDG::Goodie;
2012-05-07 18:38:06 -07:00
triggers start => 'frequency', 'freq';
2012-05-06 08:13:52 -07:00
handle remainder => sub {
if ($_)
{
my %freq;
2012-05-07 10:56:19 -07:00
my $count = 0;
2012-05-07 14:32:03 -07:00
my @chars = split //, "\L$_";
foreach (@chars)
2012-05-06 08:13:52 -07:00
{
2012-05-07 10:56:19 -07:00
if ($_ =~ /[a-z]/i)
{
2012-05-07 11:05:37 -07:00
++$freq{$_};
2012-05-07 10:56:19 -07:00
++$count;
};
2012-05-06 08:13:52 -07:00
};
my @out;
foreach my $key (keys %freq)
{
2012-05-07 18:38:06 -07:00
push @out, join ":", $key, $freq{$key} . "/" . $count;
};
return "FREQUENCY: " . join ' ',sort(@out) if @out;
2012-05-06 08:13:52 -07:00
};
return;
};
zci is_cached => 1;
1;