perlfunc
gods
<P>
exists - test whether a hash key is present
<P>
<HR>
<P>
exists
<FONT SIZE=-1>EXPR</FONT>
<P>
<HR>
<P>
Returns
<FONT SIZE=-1>TRUE</FONT> if the specified hash key exists in its hash
array, even if the corresponding value is undefined.
<P>
<PRE> print "Exists\n" if exists $array{$key};
print "Defined\n" if defined $array{$key};
print "True\n" if $array{$key};
</PRE>
<P>
<FONT SIZE=-1>A</FONT> hash element can be
<FONT SIZE=-1>TRUE</FONT> only if it's defined, and defined if it exists, but the reverse doesn't necessarily hold true.
<P>
Note that the
<FONT SIZE=-1>EXPR</FONT> can be arbitrarily complicated as long as the
final operation is a hash key lookup:
<P>
<PRE> if (exists $ref->{"A"}{"B"}{$key}) { ... }
</PRE>
<P>
Although the last element will not spring into existence just because its
existence was tested, intervening ones will. Thus <CODE>$ref->{"A"}</CODE>
<CODE>$ref->{"B"}</CODE> will spring into existence due to the existence test for a
<CODE>$key</CODE> element. This autovivification may be fixed in a later
release.
<HR>