Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Loop reference to value in hash of hash

by Dr Manhattan (Beadle)
on Jul 31, 2013 at 08:44 UTC ( #1047210=perlquestion: print w/replies, xml ) Need Help??
Dr Manhattan has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

Quick question- How do I reference a value in a hash in a hash, while I'm in a foreach loop?

foreach my $x (values %hash{}{}) { #do something }

I'm really not sure how its supposed to work and I can't find something similar on the web

Replies are listed 'Best First'.
Re: Loop reference to value in hash of hash
by choroba (Chancellor) on Jul 31, 2013 at 08:54 UTC
    %hash{}{} is a syntax error. Did you have this in mind?
    for my $x (values %hash) { print $x->{inner_key}; }

    If not, please be more specific.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Loop reference to value in hash of hash
by Loops (Curate) on Jul 31, 2013 at 08:51 UTC

    Hi there, not really sure what you're asking. In your example, the variable $x will hold the current iteration value taken from the hash. Do you need another value from the hash? If so what is it you want?

    * oops, ignoring the syntax error noted by choroba
Re: Loop reference to value in hash of hash
by Anonymous Monk on Jul 31, 2013 at 09:01 UTC
Re: Loop reference to value in hash of hash
by Anonymous Monk on Jul 31, 2013 at 12:24 UTC
    foreach my $x (values %{ $hash{somekey}{otherkey} } ) { }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1047210]
Approved by Loops
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2017-06-23 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (555 votes). Check out past polls.