不完全确定为什么,但由于某种原因,我无法在 while 循环之外打印散列值。
#!/usr/bin/perl -w
opendir(D, "cwd" );
my @files = readdir(D);
closedir(D);
foreach $file (@files)
{
open F, $file or die "$0: Can't open $file : $!\n";
while ($line = <F>) {
chomp($line);
$line=~ s/[-':!?,;".()]//g;
$line=~ s/^[a-z]/\U/g;
@words = split(/\s/, $line);
foreach $word (@words) {
$frequency{$word}++;
$counter++;
}
}
close(F);
print "$file\n";
print "$ARGV[0]\n";
print "$frequency{$ARGV[0]}\n";
print "$counter\n";
}
任何帮助将非常感激!干杯。