in reply to using hash to find frequency count
The problem lies with your split. @list contains things which aren't words, including 0-length strings.
Perhaps you should replace
my @list = split /[,.?!)"]?\s\)?/, shift;
with something like
my @list = shift =~ /([a-zA-Z'\-]+)/g;
$maxcount++;
should be
$maxcount = $count;
readline is poorly named. It doesn't read anything.
$hash{lc $word}++;
$count = $hash{lc $word};
can be simplified to
$count = ++$hash{lc $word};
sub read_file{ ... }
read_file @ARGV;
can be simplified to
while (<>) { read_line $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: using hash to find frequency count
by jjohhn (Scribe) on May 15, 2005 at 03:57 UTC | |
by jjohhn (Scribe) on May 15, 2005 at 04:07 UTC | |
by jjohhn (Scribe) on May 15, 2005 at 04:23 UTC | |
by ikegami (Patriarch) on May 15, 2005 at 13:44 UTC |