나는 a가 텍스트를 처리하고 사전에 단어 빈도를 제공 한 다음 사전을 정렬해야하는 펄 스크립트를 작성하고 있습니다. 이 텍스트는 Edgar Poe의 "Golden Bug"에서 추출한 것으로 모든 단어의 빈도를 계산하는 데 사용됩니다. 그러나 출력이 없기 때문에 나는 잘못을 저지른다. 언제 내가 잘못하고 있니? 감사.단어 빈도를 카운트 한 다음 정렬하십시오.
open(TEXT, "goldenbug.txt") or die("File not found");
while(<TEXT>)
{
chomp;
$_=lc;
s/--/ /g;
s/ +/ /g;
s/[.,:;?"()]//g;
@word=split(/ /);
foreach $word (@words)
{
if(/(\w+)'\W/)
{
if($1 eq 'bug')
{
$word=~s/'//g;
}
}
if(/\W'(\w+)/)
{
if(($1 ne 'change') and ($1 ne 'em') and ($1 ne 'prentices'))
{
$word=~s/'//g;
}
}
$dictionary{$word}+=1;
}
}
foreach $word(sort byDescendingValues keys %dictionary)
{
print "$word, $dictionary{$word}\n";
}
sub byDescendingValues
{
$value=$dictionaty{$b} <=> $dictionary{$a};
if ($value==0)
{
return $a cmp $b
}
else
{
return $value;
}
}
작은 단어 목록을 게시 할 수도 있습니까? 또한 당신은 어디에서나 % dictionary를 선언하지 않고 있습니다 ... –