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

Hi, Can anyone please explain how you can look up key-value pairs in a hash containing 2 values per key!? Preferably I would like to be able to access both values at the same time. My attempt doesn't work! Cheers monks :->
my %energy_hash = map {$amount [$_] => [$chocolate[$_] => $sweets[$_] +] } 0..$#amount; print $energy_hash {"10"}[1];

Replies are listed 'Best First'.
Re: multi-dimensional hashes
by broquaint (Abbot) on Feb 27, 2003 at 15:16 UTC
    my %mdhash = ( foo => [ qw( ichi ni ) ], bar => [ qw( san shi ) ], ); print $mdhash{foo}->[0], $mdhash{foo}[1], $/, @{$mdhash{bar}}[0], pop @{ $mdhash{bar} }, $/; __output__ ichini sanshi
    See. perlreftut and perlref for more info.
    HTH

    _________
    broquaint

Re: multi-dimensional hashes
by tachyon (Chancellor) on Feb 27, 2003 at 15:36 UTC

    You will find some nice example code here hashes ?

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print