Hashtable of arrays

Discussion in 'Perl Misc' started by Apokrif, Feb 2, 2005.

  1. Apokrif

    Apokrif Guest

    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.
     
    Apokrif, Feb 2, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandra Stehman
    Replies:
    5
    Views:
    30,912
    Chris Smith
    Jun 17, 2004
  2. Bill Reyn
    Replies:
    3
    Views:
    2,343
    Bob Hairgrove
    Jun 22, 2004
  3. Mantorok Redgormor

    initializing arrays of arrays

    Mantorok Redgormor, Sep 10, 2003, in forum: C Programming
    Replies:
    4
    Views:
    590
  4. Philipp
    Replies:
    21
    Views:
    1,189
    Philipp
    Jan 20, 2009
  5. Apokrif

    Hashtable of arrays

    Apokrif, Feb 2, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    111
    Anno Siegel
    Feb 3, 2005
Loading...

Share This Page