I am parsing a text file and store words as keys inside a hash. Each key has an array as its value and stores how many times this word appears in the text as the first value and the probability of this word as the second value in the array.
Example:
my %ngram = (
"word"=>("how many this word appear in text"," probability of this word")
);
How can I access or retrieve values of arrays inside a hash? I am posting code I used to accomplish that; I tried to print out these values, but it prints out as zeros as you see below:
0 *** 0
0 *** 0
Any clue how I can retrieve or access these values?
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;
}