From 45d8bfc2f8dbee686fea0688208e1a0760250390 Mon Sep 17 00:00:00 2001 From: unlisted Date: Mon, 7 May 2012 10:58:54 -0400 Subject: [PATCH] fixed counter, only returns string if input contains chars a-z --- lib/DDG/Goodie/Frequency.pm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/DDG/Goodie/Frequency.pm b/lib/DDG/Goodie/Frequency.pm index 5dd92c9c1..8991fe04b 100644 --- a/lib/DDG/Goodie/Frequency.pm +++ b/lib/DDG/Goodie/Frequency.pm @@ -9,16 +9,21 @@ handle remainder => sub { if ($_) { my %freq; - - my $lower = lc; - my @chars = split //,$lower; - - foreach my $char (@chars) + my @chars = split //, "\L$_"; + + foreach (@chars) { - ++$freq{$char} unless $_ eq ' '; + ++$freq{$_} if $_ =~ /[a-z]/i; }; - return "FREQUENCY: " . keys %freq if $_; + my @out; + foreach my $key (keys %freq) + { + push @out, (join ":",$key,$freq{$key}); + print "$freq{$key}\n"; + }; + + return "FREQUENCY: " . join ' ',sort(@out) if @out; }; return;