exists#

Synopsis#

if (exists $hash{$key})   { ... }
if (exists $array[$idx])  { ... }
if (exists $stash{$name}) { ... }   # stash symbol lookup

Description#

Tests whether a hash key or array index is present in the container.

Pops a key and a container (hash or array) from the stack. For hashes, checks whether the key is present (even if the associated value is undef). For arrays, checks whether the index is within bounds and the element has not been deleted. Pushes 1 (true) or 0 (false).

When the container is a stash (package symbol table accessed via %{"Package::"}), checks for the existence of any symbol type (scalar, array, hash, or code) with the given name.

See also#

defined, delete, keys