in reply to Re^4: hash to count words
in thread hash to count words
#!/usr/bin/perl -w foreach $file (@ARGV) { open (IN, $file) or die "Cannot open file '$file' : $!\n"; while(<>) { $line = <IN>; @array = split (' ', $line); foreach $word (@array){ $word =~ s/[^\w\s]//g; $word = lc ($word); $wordcount{$word} += 1; } } foreach $key (keys %wordcount) { print "Word: $key " . ($wordcount{$key}) . "\n"; } } print ("scriptOutput\n\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: hash to count words
by AnomalousMonk (Archbishop) on Sep 17, 2012 at 19:52 UTC |