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

Re: hash within an array within a hash

by kcott (Abbot)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2014-09-30 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (371 votes), past polls