关于perl的一个小程序,请大家帮忙看看
mmxxt 2003-08-30 11:16:35 我用的是aciveperl,windows me
在d根目录下放有sample.txt文件,内容为
Most left Rosehill on Saturday with the opinion, through circumstances, that the champion Northerly had a nice barrier trial in the Manion Cup for the upcoming BMW this week but rivals behind the quinella in the Ryder had a similar fresh air and gentle exercise experience for the Doncaster.
以下为counter1.pl的内容
#!/usr/bin/perl
$TheFile="d:\sample.txt";
#Open the file but quit if it doesn't exist
open(INFILE,"sample.txt") or die "The file $TheFile could not be found.\n";
#initialize the counters
$CharCount = 0;
$WordCount = 0;
$LineCount = 0;
while(<INFILE>){
$TheLine = $_;#Save the line's contents
chomp($TheLine);
$LineCount = $LineCount + 1;
$LineLen = lenth($TheLine);
$CharCount= $CharCount +$LineLen;
if($TheLine eq ""){next};
$WordCount=$WordCount + 1;
$CharPos = 0;
until($CharPos==$LineLen){
if(substr($TheLine,$CharPos,1)eq" ")
{$WordCount = $WordCount +1}
$CharPos = $CharPos +1;
}
}
print "For the file $TheFile: \n";
print "Number of characters $CharCount \n";
print "Number of words $WordCount \n";
print "Number of lines $LineCount \n";
这个程序运行时老是提示找不到文件,请问问题出在哪里呢?