home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Webmaster in a Nutshell

Previous Chapter 15
Perl Quick Reference
Next
 

15.12 Array and List Functions

delete $hash{key}

Deletes the specified value from the specified hash. Returns the deleted value (unless hash is tied to a package that does not support this).

each %hash

Returns a 2-element array consisting of the key and value for the next value of the hash. Entries are returned in an apparently random order. After all values of the hash have been returned, a null array is returned. The next call to each after that will start iterating again.

exists expr(dagger)

Checks if the specified hash key exists in its hash array.

grep expr, list

grep block list

Evaluates expr or block for each element of the list, locally setting $_ to refer to the element. Modifying $_ will modify the corresponding element from list. Returns the array of elements from list for which expr returned true.

join expr, list

Joins the separate strings of list into a single string with fields separated by the value of expr, and returns the string.

keys %hash

Returns an array of all the keys of the named hash.

map expr, list

map block list

Evaluates expr or block for each element of the list, locally setting $_ to refer to the element. Modifying $_ will modify the corresponding element from list. Returns the list of results.

pop @array

Pops off and returns the last value of the array.

push @array, list

Pushes the values of list onto the end of the array.

reverse list

In array context, returns the list in reverse order. In scalar context, returns the first element of list with bytes reversed.

scalar @array

Returns the number of elements in the array.

scalar %hash

Returns a true value if the hash has elements defined.

shift [ @array ]

Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. If @array is omitted, shifts @ARGV in main and @_ in subroutines.

sort [ subroutine ] list

Sorts the list and returns the sorted array value. subroutine, if specified, must return less than zero, zero, or greater than zero, depending on how the elements of the array (available to the routine as $a and $b) are to be ordered. subroutine may be the name of a user-defined routine, or a block.

splice @array, offset [, length [ , list ] ]

Removes the elements of @array designated by offset and length, and replaces them with list (if specified). Returns the elements removed.

split [ pattern [ , expr(dagger) [ , limit ] ] ]

Splits a string into an array of strings, and returns it. If limit is specified, splits into at most that number of fields. If pattern is also omitted, splits at the whitespace. If not in array context, returns number of fields and splits to @_. See also Search and Replace Functions.

unshift @array, list

Prepends list to the front of the array, and returns the number of elements in the new array.

values %hash

Returns a normal array consisting of all the values of the named hash.


Previous Home Next
String Functions Book Index Regular Expressions

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell