$words += scalar(split(/\s+/, $_));
If your text has leading whitespace then that will give you the number of words plus one. What you should do is:
$words += split;
To get a count of the unique words you need to use a hash:
my %unique_word_count; while ( <FILE> ) { my @words = split; $words += @words; $unique_word_count{ $_ }++ for @words; }
In reply to Re: Sorting Unique
by jwkrahn
in thread Sorting Unique
by rolandomantilla
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |