Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: How do I just count any words from a file?

by varian (Chaplain)
on Jun 04, 2007 at 14:45 UTC ( [id://619136]=note: print w/replies, xml ) Need Help??


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

print "$wordcount, $_\n";
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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://619136]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-19 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found