in reply to How do I just count any words from a file?
If it's the common or garden "delimited by cr or space", then I'd use split on a regexp to mean "1 or more of: ( space or carriage return)" (I'll follow the above trend of letting you read the docs rather than just giving the answer). You can find more about regexps in perlre.
One other point though: when reading from a file with the <> operator, what is read is determined by scalar or list context (scalar read enough for a scalar, list read whole file into a list or array) together with whatever is in the $/ variable (the record delimiter). Thus to count the number of fields in STDIN, delimited by a regexp ...
use strict; use warnings; $/=undef(); # make it read everything in the file into a scalar contex +t my @words = split /the regexp/, <>; # now the size of the array given by $#words is one less than the word +count
^M Free your mind!
|
|---|