develooper Front page | perl.beginners | Postings from February 2002

what have I gotten myself into and how do I get out

Thread Next
From:
John
Date:
February 6, 2002 13:33
Subject:
what have I gotten myself into and how do I get out
Message ID:
jUsT.aNoTheR.mEsSaGe.iD.10130312232757@jpw3.com
I believe that what my application requires is a hash of hashes that 
each reference an array of hashes.  What is the best way to rewrite 
this structure or the access to it so that I do not need one foreach 
within another?    

#!/usr/bin/perl -w

use Strict;

my %cfg = (
    "outer_key1" =>
    {   "inner_key1" =>
        [
            {   dir =>  "the_value_I_want",
            },
            {   dir =>  "another_value_I_want",
            },
        ],
    },
    "outer_keyN" =>
    {   "inner_keyN" =>
        [
            {   dir =>  "the_value_I_want",
            },
            {   dir =>  "another_value_I_want",
            },
        ],
    },
);

my $cfgs = $cfg{'outer_key'}{'inner_key'};

# I would like to be able to use
# if( ! defined( $cfgs ))
# or something here to detect an error condition and abort.

foreach my $item ( @$cfgs )
{
    foreach my $inner ( $item )
    {
        print "Inner : $inner->{'dir'}";
    }
}

__END__







Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About