raveguy2k has asked for the wisdom of the Perl Monks concerning the following question:
How could I count the number of words in my .txt file?
Here is the code I have, but it doesn't seem to work:
#!/usr/bin/perl use warnings; use strict; my($count, $pattern); my $input = shift; $pattern = \b\w+\b; open(FILE,"$input") or die "Error: $!\n"; $count = 0; while(<FILE>) { if(/$pattern/) { $count++; } } print "Word Count = ", $count, "\n\n";
Any suggestions?
Back to
Seekers of Perl Wisdom