daemonchild has asked for the wisdom of the Perl Monks concerning the following question:

ok, i'm stuck on this one. normally i'd plug away at it until i figure it out, but i'm in a bit of a hurry to finish this off (damn deadlines). help would be much appreciated.

i'm trying to decipher some code, and something is not making sense to me. so here we go (the comments are mine) ...
$array = [] #returns a ref to an anonymous array push @{$array}, { key => "$val", key2 => "$val2" }; #huh?
correct me if i'm wrong ... but from what i can figure, an anonymous numeric array ref is being deferenced, then populated with hash array data?

if not, how do i get data out of this? i don't really feel like using the trial and error method ... i'd like to actually understand what's going on.

my apologies if this is somewhat of an obvious question ... i checked through a bunch of documentation, and found no mention of this ...

thanks

-- steve

Replies are listed 'Best First'.
Re: array refs, hashes, and confusion
by suaveant (Parson) on Aug 03, 2001 at 00:13 UTC
    $array holds an anonymous array ref... @{$array} derefs $array allow you to push an anonymous hash onto said anonymous array, you would access key2 in your example with
    $array->[0]{key2};
    That help?

                    - Ant

      wow!

      i come back from my lunch break, and my question is answered ... i'm impressed.

      that worked perfectly ... many thanks

      -- steve

Re: array refs, hashes, and confusion
by runrig (Abbot) on Aug 03, 2001 at 00:14 UTC
    perldoc perldata is your friend (TMTOWTDI):
    $array->[0]->{key1} or #(any arrows after the first dereference are optional) $array->[0]{key1} or $$array[0]->{key1} or $$array[0]{key1}
Re: array refs, hashes, and confusion
by VSarkiss (Monsignor) on Aug 03, 2001 at 00:18 UTC

    Actually, what's being pushed into the anonymous array is a reference to an anonymous hash containing those keys and values. You can get the value of $val with something like $array->[0]{key}.

    HTH

Re: array refs, hashes, and confusion
by daemonchild (Acolyte) on Aug 03, 2001 at 01:26 UTC
    thanks all!

    problem solved ... i guess my documentation searching skills need a bit of work. : )

    -- steve