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

Two parts: A) is it possible B) how do I reference the hashes and their associated values

Replies are listed 'Best First'.
Re: Array of hashes
by stephen (Priest) on Apr 26, 2002 at 03:53 UTC

    A)Yes, B) Like so:

    my @superfriends = ( { name => 'aquaman', power => 'talks to fish' }, { name => 'zan', power => 'can turn into water or ice' }, ); # To access the name of the second superfriend in list print "Name: $superfriends[1]{'name'}\n";
    Note: Code not tested, and superfriends powers not double-checked.

    Technically, it's an array of hash references, but hey...

    stephen

Re: Array of hashes
by mce (Curate) on Apr 26, 2002 at 08:14 UTC
    hi,
    Or to please Larry, Tom and Jon. chapter 8.
    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium
Re: Array of hashes
by George_Sherston (Vicar) on Apr 26, 2002 at 15:07 UTC
    Here's the answer to a question you didn't ask but may want to: if you want to see what's in your array of hashes or other comples data structure (e.g. to find out whether you created it successfully) then this will give you happiness:
    use Data::Dumper; print Dumper(\@your_array);
    NB, this is a snippet - I assume you have created your array under strict etc (I say this to protect myself from the wrath of sibling monks!).

    George Sherston
Re: Array of hashes
by BUU (Prior) on Apr 26, 2002 at 05:12 UTC