Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by princepawn (Parson)
on Jun 04, 2007 at 13:25 UTC ( [id://619120]=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?

I suspected your \b was un-necessary and the following test file implies that it does...
use strict; my $line = 'hi there my name is bob'; sub m1 { my $line = shift; my $re = '(\w+)' ; my @match = ( $line =~ /$re/g ) ; return scalar @match ; } sub m2 { my $line = shift; my $re = '\b\w+\b' ; my $wordcount; $wordcount++ while $line =~ /$re/g ; return $wordcount ; } sub m3 { my $line = shift; my $re = '\w+' ; my $wordcount; $wordcount++ while $line =~ /$re/g ; return $wordcount ; } print m1($line); print m2($line); print m3($line);


Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found