Ed,
 A 'cleaner' approach.

#!/usr/bin/perl -w

use strict;
my %hash = (
  fruits => {
     favorite     => "apples",
     'second favorite' => "oranges",
     },
  vegetables => {
     favorite     => "corn",
     'second favorite' => "peas",
     'least favorite'  => "turnip",
     },
  meats => {
    favorite     => "chicken",
    'second favorite'  => "beef",
    },
  );
# explicit printing
print $hash{meats}->{favorite}, "\n";
print $hash{meats}->{'second favorite'}, "\n";
print $hash{vegetables}->{'least favorite'}, "\n";
print $hash{vegetables}->{'second favorite'}, "\n";
print $hash{vegetables}->{favorite}, "\n";
print $hash{fruits}->{favorite}, "\n";
print $hash{fruits}->{'second favorite'}, "\n";
my @ohk = qw( meats vegetables fruits ); # outer hash keys
my @ihk = ( 'favorite', 'second favorite', 'least favorite' ); # inner hash
keys
print "Finally\n\n";
# Finally something you might actually use
for my $ohk (@ohk) {
 print"$ohk\n";
 for my $ihk (@ihk) {
  print "\t$ihk: ", $hash{$ohk}->{$ihk}, "\n" if exists $hash{$ohk}->{$ihk};
 }
}
--end of code--
The central (as opposed to key) point:
In the expression:
$hash{$ohk}->{$ihk}
$hash{$ohk} is the _value_ of a hash, but that _value_ is a reference to a
hash,
so we can use the '->' syntax. Think of:
$hash{$ohk}->
as identifying that (pesky anonymous) hash for us. Then the {$ihk} simply
identifies the value of that hash we want to print.
HTH




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to