### perlfunc:exists

by gods
 on Aug 24, 1999 at 22:42 UTC ( #253=perlfunc: print w/replies, xml ) Need Help??

# exists

See the current Perl documentation for exists.

Here is our local, out-dated (pre-5.6) version:

exists - test whether a hash key is present

exists EXPR

Returns TRUE if the specified hash key exists in its hash array, even if the corresponding value is undefined.

    print "Exists\n" if exists $array{$key};
print "Defined\n" if defined $array{$key};
print "True\n" if $array{$key};


A hash element can be TRUE only if it's defined, and defined if it exists, but the reverse doesn't necessarily hold true.

Note that the EXPR can be arbitrarily complicated as long as the final operation is a hash key lookup:

    if (exists $ref->{"A"}{"B"}{$key}) { ... }


Although the last element will not spring into existence just because its existence was tested, intervening ones will. Thus $ref->{"A"} $ref->{"B"} will spring into existence due to the existence test for a \$key element. This autovivification may be fixed in a later release.

Create A New User
Chatterbox?
 [Corion]: thezip: If you want to open vim and can live with opening a second console window, use start "The results" vim.exe c:\path\to\logfile .log [thezip]: Ooops... I lied. I guess Cygwin is back. I'll just do a tail -f instead. Better. Sorry for the noise.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2017-03-27 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (321 votes). Check out past polls.