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
In reply to Re: hash within an array within a hash
by kcott
in thread hash within an array within a hash
by jwexfyfz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |