#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Posts
    7
    Rep Power
    0

    Question


    If I throw an array inside of a hash:
    %somehash = ('somekey', ['one', 'two'])

    how do I get the array back out? I get can individual values from the array with:
    $somehash{somekey}[0]

    but if I try to get the entire array:
    @somehash{somekey}

    I get some funky array junk:
    Arrayx18748210


    Any ideas?
  2. #2
  3. Ole` Timer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    N.W. Iowa
    Posts
    472
    Rep Power
    15
    Try:
    @{$somehash{somekey}}

    That will give you back your array of "one two".

    Mickalo

    Thunder Rain Internet Publishing

    Custom Programming & Database development
    Providing Personal/Business
    Internet Solutions that work!
  4. #3
  5. No Profile Picture
    PerlGuy
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2001
    Posts
    720
    Rep Power
    42

    Wink


    I would do some research on references with Perl. When you tried:
    Code:
    @somehash{somekey}
    and got back:
    Code:
    ARRAYx18748210
    You were dealing with references. Your result was a description of the data type held in a memory address - ARRAY - and the actual memory address - x18748210. This is a reference or a "pointer" to the address that a variable is stored in. References are good for saving memory space and CPU time.

    You did it in a really funky way. With a non-referenced HASH but a referenced element to that hash. A more consistent way to do this would have been.
    [code]
    $somehash = {
    'somekey' => ["one","two"],
    'anotherkey' => ["three","four"],
    };

    print @{$somehash->{'somekey'}}, "\n"; # This would dereference and print one of your entire arrays
    - dsb -
    Perl Guy
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Posts
    7
    Rep Power
    0
    That's the ticket. Thanks guys.

IMN logo majestic logo threadwatch logo seochat tools logo