Wednesday, January 9, 2008

Array Functions

Here are the functions you can use with arrays:

* defined(VARIABLE) -- Returns true if VARIABLE has a real value and if the variable has not yet been assigned a value. This is not limited to arrays; any data type can be checked. Also see the exists function for information about associative array keys.
* delete(KEY) -- Removes the key-value pair from the given associative array. If you delete a value from the %ENV array, the environment of the current process is changed, not that of the parent.
* each(ASSOC_ARRAY) -- Returns a two-element list that contains a key and value pair from the given associative array. The function is mainly used so you can iterate over the associate array elements. A null list is returned when the last element has been read.
* exists(KEY) -- Returns true if the KEY is part of the specified associative array. For instance, exists($array{"Orange"}) returns true if the %array associative array has a key with the value of "Orange."
* join(STRING, ARRAY) -- Returns a string that consists of all of the elements of ARRAY joined together by STRING. For instance, join(">>", ("AA", "BB", "cc")) returns "AA>>BB>>cc".
* keys(ASSOC_ARRAY) -- Returns a list that holds all of the keys in a given associative array. The list is not in any particular order.
* map(EXPRESSION, ARRAY) -- Evaluates EXPRESSION for every element of ARRAY. The special variable $ is assigned each element of ARRAY immediately before EXPRESSION is evaluated.
* pack(STRING, ARRAY) -- Creates a binary structure, using STRING as a guide, of the elements of ARRAY. You can look in the next Chapter on References for more information.
* pop(ARRAY) -- Returns the last value of an array. It also reduces the size of the array by one.
* push(ARRAY1, ARRAY2) -- Appends the contents of ARRAY2 to ARRAY1. This increases the size of ARRAY1 as needed.
* reverse(ARRAY) -- Reverses the elements of a given array when used in an array context. When used in a scalar context, the array is converted to a string, and the string is reversed.
* scalar(ARRAY) -- Evaluates the array in a scalar context and returns the number of elements in the array.
* shift(ARRAY) -- Returns the first value of an array. It also reduces the size of the array by one.
* sort(ARRAY) -- Returns a list containing the elements of ARRAY in sorted order. See next Chapter 8on References for more information.
* splice(ARRAY1, OFFSET, -- Replaces elements of ARRAY1 with elements LENGTH, ARRAY2)in ARRAY2. It returns a list holding any elements that were removed. Remember that the $[ variable may change the base array subscript when determining the OFFSET value.
* split(PATTERN, STRING, LIMIT) -- Breaks up a string based on some delimiter. In an array context, it returns a list of the things that were found. In a scalar context, it returns the number of things found.
* undef(VARIABLE) -- Always returns the undefined value. In addition, it undefines VARIABLE, which must be a scalar, an entire array, or a subroutine name.
* unpack(STRING, ARRAY) -- Does the opposite of pack().
* unshift(ARRAY1, ARRAY2) -- Adds the elements of ARRAY2 to the front of ARRAY1. Note that the added elements retain their original order. The size of the new ARRAY1 is returned.
* values(ASSOC_ARRAY) -- Returns a list that holds all of the values in a given associative array. The list is not in any particular order.

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my site, it is about the CresceNet, I hope you enjoy. The address is http://www.provedorcrescenet.com . A hug.