T
Tiro Verus
Can this be done?
I've been trying to count the number of times a given word
appears in an ASCII file. This works for most terms:
==============================
my $search_term = shift;
my $count = 0;
while (<>) {
while (m/\b$search_this\b/g) {
$count++;
}
}
================================
But it doesn't take input search terms beginning with $
such as $fn. I've tried
$./wordcount.pl \$fn textfile
and
$./wordcount.pl '\$fn' textfile
as well as
$./wordcount.pl $fn textfile
Which gives the message "undefined variable" or something like that.
Or the output says " textfile does not contain $fn" when it does.
That was for the '$fn' version. But 'fn' in @ARGV works just fine.
[The code lines with the result msgs have been snipped]
I cannot find anything about this in the Camel Book or the
Cookbook. BTW
$ grep '\$fn' textfile
finds all the lines with "$fn" in them, but I need an occurrence count.
I've been trying to count the number of times a given word
appears in an ASCII file. This works for most terms:
==============================
my $search_term = shift;
my $count = 0;
while (<>) {
while (m/\b$search_this\b/g) {
$count++;
}
}
================================
But it doesn't take input search terms beginning with $
such as $fn. I've tried
$./wordcount.pl \$fn textfile
and
$./wordcount.pl '\$fn' textfile
as well as
$./wordcount.pl $fn textfile
Which gives the message "undefined variable" or something like that.
Or the output says " textfile does not contain $fn" when it does.
That was for the '$fn' version. But 'fn' in @ARGV works just fine.
[The code lines with the result msgs have been snipped]
I cannot find anything about this in the Camel Book or the
Cookbook. BTW
$ grep '\$fn' textfile
finds all the lines with "$fn" in them, but I need an occurrence count.