in reply to Re: How do I just count any words from a file?
in thread How do I just count any words from a file?
The regular expression isn't an array you can foreach through. It returns something like a true false value while the iterator is true instead.Not true, the OP used the 'g' flag which makes the regexp return a list of matched groupings when in list context (and foreach expects a list).
So to combine foreach with a regexp is just fine, in fact Cazbo you are close to the solution!
Hint: to debug execute a
within your foreach loop immediately after you do the autoincrement and see what it prints. Your regexp needs some finetuning and what about the counter itself?print "$wordcount, $_\n";
|
|---|