Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Array of hashes

by straywalrus (Friar)
on Apr 26, 2002 at 03:46 UTC ( [id://162170]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://162170]
Approved by mce
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found