dbmathis has asked for the wisdom of the Perl Monks concerning the following question:

I can't seem to get into the second for loop.. Does anyone see my problem?

sub get_rc_site_information { for my $instance ( keys %site_information ) { print $instance; for my $schema ( keys %{ $site_information->{ $instance } } ) +{ print $schema; my $channel_query = qq(select
Instance1Instance2 $VAR1 = { 'Instance1' => { 'schema1' => { 'tomcat' => 'aus02tc085' } }, 'Instance2' => { 'schema1' => { 'tomcat' => 'aus02tc032' }, 'schema2' => { 'tomcat' => 'aus02tc087'
After all this is over, all that will really have mattered is how we treated each other.

Replies are listed 'Best First'.
Re: Help looping through hash
by ikegami (Patriarch) on May 14, 2011 at 00:38 UTC

    use strict; catches your error. You switch from using %site_information to using %$site_information

    By the way, to dump hashes, pass a reference to the hash to Dumper (e.g. Dumper(\%hash)). What you did isn't as readable.

      I don't follow, I am making use of use strict and there is nothing being caught. I have done it like this many times. What happens here is that the inner loop simple doesn't iterate. The second for loop switches to $site_information because I am using %{}. Can you give me an example?

      After all this is over, all that will really have mattered is how we treated each other.

        I don't follow, I am making use of use strict and there is nothing being caught

        Then you've discovered why it's a bad idea to have a two identically-named global variables (%site_information and $site_information).

        This was the fix

        sub get_rc_site_information { for my $instance ( keys %site_information ) { print $instance; for my $schema ( keys %{ $site_information{ $instance } } ) { print $schema; my $channel_query = qq(select
        After all this is over, all that will really have mattered is how we treated each other.