Hashtable of arrays

A

Apokrif

I've got a lexicon file which contains lines such as "chaise,
fauteuil=seat, chair" (one or several [more or less] synonymous French
words on the left, and their translation on the right). I'm trying to
build a hashtable that uses the French word as a key, and returns a
list containing English translations:

chaise=>(chair,seat)
fauteuil=>(chair,seat)

I wrote::

%translations=();
while (<FILE>){
chomp;
($left, $right)=split(/=/,$_);
@words_on_the_left=split (/, /, $left);
@words_on_the_right=split (/, /, $right);
for $word (@words_on_the_left){
if (!defined($translations{$word}))
{
$translations{$word}=@words_on_the_right;
}else{
$translations{$word}=($translations{$word}, @words_on_the_right);


}
print $translations{$word};
}

}


This doesn't work: instead of displaying English translations, the
script prints a list of numbers (which lets me think that the lists
are interpreted in a scalar context.) I tried to adapat examples I
found on the Web and I replaced in several places "$" with "@" or with
"@{$", and I also tried to replace
"$translations{$word}=($translations{$word}, @words_on_the_right);"
with "$translations{$word}=($translations{$word},
\@words_on_the_right);", but I don't get the results I expected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top