At 10:56 AM -0500 2/6/03, Joel Gwynn wrote:
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:
Makes sense. It can hardly look to see if the subhash exists without
first creating the element. The alternative would be to get a null
from the first item and then try and dereference it and get an error.
Weird, but logical.This works fine.
#!/usr/bin/perl
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 $apples{$t} && $apples{$t}->{weight};
}
print "\n-----------------------\n";
foreach my $a (keys %apples) {
print "$a: weight: $apples{$a}->{weight}\n";
}
--
Kee Hinckley
http://www.puremessaging.com/ Junk-Free Email Filtering
http://commons.somewhere.com/buzz/ Writings on Technology and Society
I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

