Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Hashtable of arrays

Reply
Thread Tools

Hashtable of arrays

 
 
Apokrif
Guest
Posts: n/a
 
      02-02-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
Hashtable of arrays Apokrif Perl Misc 3 02-03-2005 08:17 PM
char arrays and integer arrays... why the difference? Bill Reyn C++ 3 06-22-2004 12:01 PM
Arrays.asList() returning java.util.Arrays$ArrayList Alexandra Stehman Java 5 06-17-2004 06:04 PM



Advertisments