Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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

Comment on Loop reference to value in hash of hash
Download Code
Re: Loop reference to value in hash of hash
by Loops (Chaplain) 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 choroba (Abbot) 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 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2014-10-22 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls