0
我解析一个文本文件,并将单词存储为一个散列中的键。每个键都有一个数组作为其值,并将该单词出现在文本中的次数作为第一个值,并将该单词的概率作为数组中的第二个值。如何在哈希中访问数组中的元素?
例子:
my %ngram = (
"word"=>("how many this word appear in text"," probability of this word")
);
我怎样才能哈希内访问或获取阵列的价值?我发布了我用来完成这个任务的代码;我试着打印出这些值,但是它打印出为零,你看下面:
0 *** 0
0 *** 0
任何线索我怎么可以检索或访问这些值?
while (scalar @words > $inputs[0])
{
$numerator="@words[0 .. $inputs[0]]";
$denominator= "@words[0 .. ($inputs[0]-1)]";
$nGram{$numerator}[0]=$nGram{$numerator}->[0]++;
$nGram{$denominator}++;
my $freq=$nGram{$numerator}->[0]/$nGram{$denominator};
$nGram{$numerator}[1]=$freq;
print "$nGram{$numerator}->[0] *** $nGram{$numerator}->[1]";
shift @words;
}