I call a subroutine with a reference to a hash element.
In the subroutine I want to test if the element exists.
If so, I want to get the key and the value of the element.
I can't figure out the correct syntax.
So far I can only get the value. Could someone prompt me ?

Thanks

#!perl -w
use strict; $\ = "\n";
my %H;
$H{one}{two}{three} = 'nut';
print exists $H{one}{two}{three}; # 1
cat(\$H{one}{two},'three');
dog(\$H{one}{two}{three});

sub cat{
        print $_[1]; # three
#       exists ${$_[0]}; # not a HASH element
#       exists ${$_[0]}{$_[1]}; # not a HASH reference
#       exists ${$_[0]}{"$_[1]"}; # not a HASH reference
#       exists $_[0]{"$_[1]"}; # not a HASH reference
}1;
sub dog{
        print ${$_[0]}; # nut
#       exists $_[0]; # not a HASH element
#       exists ${$_[0]}; # not a HASH element
#       exists ${${$_[0]}}; # not a HASH element
}1;

Reply via email to