, , :
scalar %h
%h ? "yup" : "nope"
scalar keys %haccomplishes the same goal by counting keys in %h, but it’s better to ask what you really want to know.
In any case, it %his a hash, not a hashref. (Although some versions of Perl allow hashref as an argument for keys.) Given an expression EXPRthat evaluates hashref, you get the corresponding hash by saying %{ EXPR }. Putting this along with your sample code, we get
print "size of hashref: " . keys( %{ $self->{href} } ) . ".\n";
print "hash " . (%{ $self->{href} } ? "does" : "does not") . " contain elements\n";
darch source
share