Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

exists

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.

Synopsis

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

See Also

defined, delete, keys