> Now, what's driving me crazy is that the two test values are being added
> to the hash, simply by looking for $apples{$t}{weight}.  If I simply
> look for $apples{$t}, like so:

I remember reading something about this. This is due to autovivification of
the the $apples{$t} value in order to look for the weight key. I don't
recall why it does this. The solution would be to check for the apple key
first and then the weight. Like this:

my %apples = (macintosh => {weight => '10lb', cost => '5'},
              red_delicious => {weight => '15lb', cost => '2'},
              fuji => {weight => '12lb', cost => '7'});

my @test = qw(granny_smith crabapple);

foreach my $t (@test){
 print "$t not found\n" unless exists $apples{$t} && $apples{$t}{weight}
}
print "\n-----------------------\n";

foreach my $a (keys %apples){
    print "$a: weight: $apples{$a}{weight}\n";
}

Grant M.

_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to