Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: hash within an array within a hash

by kcott (Canon)
on Sep 07, 2012 at 06:54 UTC ( #992254=note: print w/ replies, xml ) Need Help??

in reply to hash within an array within a hash

How would I print "Santa Claus" (name of owner1Ref) by accessing it through account?
print $account{owners}[0]{name};

You don't need the additional syntax shown in earlier replies: nested braces; dereferencing (->); quoting.

Here's my test:

$ perl -Mstrict -Mwarnings -le ' # Braces denote an anonymous hash my $owner1Ref = { "name" => "Santa Claus", "DOB" => "1882-12-25", }; my $owner2Ref = { "name" => "Mickey Mouse", "DOB" => "1928-11-18", }; # Square brackets denote an anonymous array my $ownersRef = [ $owner1Ref, $owner2Ref ]; my %account = ( "number" => "12345678", "opened" => "2000-01-01", "owners" => $ownersRef, ); print $account{owners}[0]{name}; ' Santa Claus

See also: perldsc - Perl Data Structures Cookbook

-- Ken

Comment on Re: hash within an array within a hash
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992254]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2015-11-28 16:54 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls