关于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";



这个程序运行时老是提示找不到文件,请问问题出在哪里呢?
...全文
38 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yakai 2003-08-31
  • 打赏
  • 举报
回复
调试的时候看一下$TheFile的内容,难道出了错你不调试的么?
1q1 2003-08-31
  • 打赏
  • 举报
回复
把 $TheFile="d:\sample.txt";

改成 $TheFile="d:\\sample.txt";
再试试

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧