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 (Cardinal) 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} } ) { }