Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: printing all values in a hash of hashes of arrays

by GrandFather (Saint)
on Dec 15, 2014 at 19:51 UTC ( [id://1110401]=note: print w/replies, xml ) Need Help??


in reply to printing all values in a hash of hashes of arrays

Hashes and array elements are scalar values so can only hold references to nested hashes or arrays. Therefore hash_of_hash_of_arrays{$outerkey} is a reference to a hash. To get the hash you need for keys you need to dereference it using %{}: %{$hash_of_hash_of_arrays{$outerkey}}.

Note that $, % and @ don't tell you what type variables are, they tell you what type of thing an expression returns. So $ref returns a scalar which may be a reference to an array or a hash. @$ref and @{$ref} return arrays (they are equivalent) by dereferencing $ref. The {} version is much clearer (and often required) when the expression used to get the reference is complicated.

Perl is the programming world's equivalent of English

Replies are listed 'Best First'.
Re^2: printing all values in a hash of hashes of arrays
by BillKSmith (Monsignor) on Dec 15, 2014 at 21:08 UTC

    Perl's own documentation on this subject is very good. (Refer to the section "Using References" of perldoc perlref

    Grandfather is recommending rule 2 because it always works. The other rules are essentially "short cuts" which apply in special cases.
    Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found