in reply to Word Counting
my %count; my $size = 4; # minimum size of words to count while (<>) { my @words = split; foreach my $word (@words) { next if length($word) < $size; # Count only "real" words, and words with # hyphens and apostrophes, like /foo-bar/ # and /don't/ and /ma'am/ $count{$word}++ if $word =~ m/^[a-z][A-Z]+([-'][a-z][A-Z]+)*$/; } } my %uniq = keys %count; unless (%uniq) { die "No words in the file\n"; } foreach my $word (keys %count) { $final_count += $count{$word}; $final_length += length($word); } # Do some other stuff with your hash
Update: Fixed a small typo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Word Counting
by Anonymous Monk on Apr 25, 2003 at 03:51 UTC |