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);
In reply to Re^2: How do I just count any words from a file?
by princepawn
in thread How do I just count any words from a file?
by Cazbo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |