Perl Programming/Keywords/exists

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: exec Keywords Next: exit

The exec keyword[edit | edit source]

exists returns true, if an expression that specifies an element of a hash exists, and the specified element in the hash has been initialized to any value (like undef).

Although exists can be called on arrays also, its behaviour strongly depends to the use of delete on arrays, having a much less clear behaviour.

Syntax[edit | edit source]

  exists EXPRESSION

Examples[edit | edit source]

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

See also[edit | edit source]

Previous: exec Keywords Next: exit