<?xml version="1.0" encoding="windows-1252"?>
<node id="253" title="perlfunc:exists" created="1999-08-24 18:42:34" updated="2005-08-15 07:56:50">
<type id="119">
perlfunc</type>
<author id="114">
gods</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
exists - test whether a hash key is present

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
exists 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt;

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="description">

&lt;P&gt;
Returns 
&lt;FONT SIZE=-1&gt;TRUE&lt;/FONT&gt; if the specified hash key exists in its hash
array, even if the corresponding value is undefined.

&lt;P&gt;
&lt;PRE&gt;    print &amp;quot;Exists\n&amp;quot; if exists $array{$key};
    print &amp;quot;Defined\n&amp;quot; if defined $array{$key};
    print &amp;quot;True\n&amp;quot; if $array{$key};
&lt;/PRE&gt;
&lt;P&gt;

&lt;FONT SIZE=-1&gt;A&lt;/FONT&gt; hash element can be 
&lt;FONT SIZE=-1&gt;TRUE&lt;/FONT&gt; only if it's defined, and defined if it exists, but the reverse doesn't necessarily hold true.

&lt;P&gt;
Note that the 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; can be arbitrarily complicated as long as the
final operation is a hash key lookup:

&lt;P&gt;
&lt;PRE&gt;    if (exists $ref-&amp;gt;{&amp;quot;A&amp;quot;}{&amp;quot;B&amp;quot;}{$key}) { ... }
&lt;/PRE&gt;
&lt;P&gt;
Although the last element will not spring into existence just because its
existence was tested, intervening ones will. Thus &lt;CODE&gt;$ref-&amp;gt;{&amp;quot;A&amp;quot;}&lt;/CODE&gt;

&lt;CODE&gt;$ref-&amp;gt;{&amp;quot;B&amp;quot;}&lt;/CODE&gt; will spring into existence due to the existence test for a
&lt;CODE&gt;$key&lt;/CODE&gt; element. This autovivification may be fixed in a later
release.

&lt;HR&gt;
</field>
</data>
</node>
