Hash tables

Discussion in 'Perl' started by Guillermo, Mar 1, 2004.

  1. Guillermo

    Guillermo Guest

    I dont know how can I store and recover data to/from a hash table
    which values are arrays.

    Is it OK?

    my %data = ();
    my @attributes = ();
    for($counter=1;$counter<@field;$counter++){
    $attr = <DB>;
    push(@attributes, $attr);
    }

    $data{$node} = @attributes;
    $node = <DB>;
    }

    I cant recover the values stored in the hash table
    Guillermo, Mar 1, 2004
    #1
    1. Advertising

  2. Guillermo wrote:
    > I dont know how can I store and recover data to/from a hash table
    > which values are arrays.


    perldoc perlreftut
    perldoc perlref

    I don't understand what the code you posted is supposed to do, but I
    noticed that you tried to assign an array to a hash element:

    > $data{$node} = @attributes;


    which can't be done. You need to assign a reference to the array:

    $data{$node} = \@attributes;

    Guess you have some reading to do.

    Good luck!

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Mar 1, 2004
    #2
    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. Peter Bassett
    Replies:
    3
    Views:
    912
    Augustus
    Aug 15, 2003
  2. Otuatail

    Tables within tables

    Otuatail, Jul 31, 2004, in forum: HTML
    Replies:
    7
    Views:
    483
  3. Chris Brat
    Replies:
    5
    Views:
    687
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=
    Aug 22, 2006
  4. rp
    Replies:
    1
    Views:
    493
    red floyd
    Nov 10, 2011
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    596
    David A. Black
    Jul 2, 2008
Loading...

Share This Page