I'm trying to do a function in Perl (see below) able verify the existence of each word in the hash (%emailWords) over the hash (%cache). If the word from %emailWords is not in the %cache but the method belongsTo returns true %cache hashmap must be updated with the new $word. However, altough I pass the %cache hashmap as reference, the value outside the function is empty.
sub computeConceptsUntilLevel{
my $hashRef = shift;
my $wordnetRef = shift;
my $cacheRef = shift;
my $deepLevel = shift;
my %emailWords = %{$hashRef};
my @conceptsArray = @{$wordnetRef};
my %cache = %{$cacheRef};
my @toret = ();
for (my $i=0;$i<$deepLevel;$i++){
my %conceptsMap = ();
foreach my $concept (@{$conceptsArray[$i]}){
foreach my $word (keys %emailWords) {
print "[$i]->Palabra: $word - Concepto: $concept\n";
if (wordHasConcept(\%cache,$word,$concept,$i)){
push @{$conceptsMap{$concept}}, $word;
}else{
if (defined($word) and belongsTo($word,$concept)){
push @{$conceptsMap{$concept}}, $word;
push @{$cache{$word}{$i}}, $concept;
}
}
}
}
$toret[$i] = \%conceptsMap;
}
return @toret;
}
Inside the function the %cache looks like:
$VAR1 = {
'cat' => {
'1' => [
'physical_entity#n#1'
],
'0' => [
'entity#n#1'
]
},
'duck' => {
'1' => [
'physical_entity#n#1'
],
'0' => [
'entity#n#1'
]
}
};
But outside is $VAR1={}.
What I'm doing wrong?