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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Counting words
by fruiture (Curate) on Aug 23, 2002 at 23:03 UTC | |
by PodMaster (Abbot) on Aug 24, 2002 at 11:48 UTC | |
by wog (Curate) on Aug 24, 2002 at 05:27 UTC | |
Re: Counting words
by PetaMem (Priest) on Aug 24, 2002 at 20:25 UTC | |
by GrayMagiker (Initiate) on Apr 12, 2006 at 18:58 UTC |
Back to
Seekers of Perl Wisdom