Chapter 21. Array and Hash Functions

defined expr

Not specifically an array or hash function, but provides a convenient way to test whether an array or hash element has a defined value.

delete lku
delete @array[index1, . . . ]
delete @hash{key1, key2, . . . }

lku must be an array lookup like $array[index] or expr->[index], or a hash key lookup like $hash{key} or expr->{key}. Deletes the specified elements from the array or hash. Returns aliases to the deleted values. Deleting the last element(s) of an array will shorten the array.

each %hash

In list context, returns a two-element list consisting of the key and an alias to the value for the next element of the hash. In scalar context, returns only the key. Entries are returned in an apparently random order. After all values of the hash have been returned, an empty list is returned. The next call to each after that will start iterating again. A call to keys or values will reset the iteration.

exists lku

lku must be an array a hash lookup (see delete above). Checks whether the specified array element or hash key exists.

grep expr, list
grep block list

Evaluates expr or block for each element of the list, locally aliasing $_ to the element. In list context, returns the list of elements from list for which expr or block returned true. In scalar context, returns the number of such elements.

join expr, list

Returns the string formed by inserting expr between all elements of list and concatenating the result.

keys %hash

In list context, returns a list ...

Get Perl Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.