E
elhombre
I'm sure this is a typical newbie error but I cannot see why this prints
FILE wordcount is 17 when it should print c:\original.txt word count is 17.
If I try
print $_ . " word count is " . $wordCount . "\n";
it complains that $_ is unitialised and I cannot see why.
Any ideas ?
foreach (@ARGV) {
open(FILE, $_) or die "File $_ does not exist";
while (<FILE>) {
my @words = split;
foreach my $word (@words) {
$wordCount++;
}
}
print FILE . " word count is " . $wordCount . "\n";
close FILE;
$wordCount = 0;
}
FILE wordcount is 17 when it should print c:\original.txt word count is 17.
If I try
print $_ . " word count is " . $wordCount . "\n";
it complains that $_ is unitialised and I cannot see why.
Any ideas ?
foreach (@ARGV) {
open(FILE, $_) or die "File $_ does not exist";
while (<FILE>) {
my @words = split;
foreach my $word (@words) {
$wordCount++;
}
}
print FILE . " word count is " . $wordCount . "\n";
close FILE;
$wordCount = 0;
}