注册 登录
编程论坛 Perl论坛

请问我这个程序有啥问题。执行下来,wordlist里面是空白。请哪位朋友指点一下。

nielong1964 发布于 2011-10-11 20:29, 5883 次点击



!/usr/bin/perl

open (FH, 'F:\\perl\about BUCT.txt ') || die $!;
open (OUT,'>>','F:/perl/wordlist.txt')or die $!;
sub byDescendingValues{
 $value= $freq{$b}<=>$freq{$a};
if ($value==0){
return $a cmp $b;
}else{
return $value;
}
}

while(<FH>) {
   {$line=$_ ;
        chomp $line;
        @words = split (/[\.\?,!;:]+\s+/, $line);}

        foreach $x (@words) {
              ++ $wordfreq{$x};
              }
              }
        close FH;

          foreach $x(sort byDescendingValues keys %freq){

   print OUT "$x,$wordfreq{$x}\n";
   }
1 回复
#2
sianeal2012-02-25 20:09
是这里有问题吧,'F:\\perl\about BUCT.txt ',反斜杠在单引号中应该写成双的 \\ ,否则不按路径执行。
1