From a1e21f0d7c428c47cd4da5efdc8012857ecfaee6 Mon Sep 17 00:00:00 2001 From: unlisted Date: Mon, 7 May 2012 13:56:19 -0400 Subject: [PATCH] added decimal frquency/letters --- lib/DDG/Goodie/Frequency.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/DDG/Goodie/Frequency.pm b/lib/DDG/Goodie/Frequency.pm index 8991fe04b..6c53e7166 100644 --- a/lib/DDG/Goodie/Frequency.pm +++ b/lib/DDG/Goodie/Frequency.pm @@ -9,18 +9,25 @@ handle remainder => sub { if ($_) { my %freq; + my %perc; my @chars = split //, "\L$_"; + my $count = 0; foreach (@chars) { - ++$freq{$_} if $_ =~ /[a-z]/i; + if ($_ =~ /[a-z]/i) + { + ++$freq{$_} if $_; + ++$count; + }; }; my @out; foreach my $key (keys %freq) { - push @out, (join ":",$key,$freq{$key}); - print "$freq{$key}\n"; + #$perc{$key} = $freq{$key} / $count; + #my $rec = join ":", $key, $freq{$key}; + push @out, join " ", (join ":", $key, $freq{$key}), ($freq{$key} / $count); }; return "FREQUENCY: " . join ' ',sort(@out) if @out;