- @name in a list context refers to the array's entire
contents as a list.
@a = (7, 8, 9);
($b) = @a;
Sets
$b to 7.
- @name in a scalar context refers to the array length
(number of elements).
@a = (7, 8, 9);
$b = @a;
Sets
$b to 3.
- $name[identifier] refers to
one element of the array; index zero is the first element.
@a = (7, 8, 9);
$b = $a[1];
Sets
$b to 8.
- $#name gives the index of the last element.
@a = (7, 8, 9);
$b = $#a;
Sets
$b to 2.
- List literals can be used on both sides of an assignment.
($a, $b, $c) = (1, 2, 3);
Sets
$a to 1, $b to 2, and $c to 3.
- join(text,@name)
concatenates an array into one long string, with text between each
element.
@a = (7, 8, 9);
$b = join("+",
@a);
Sets $b to "7+8+9".
- split(/regex/,$name) splits
a string into its separate elements, separated by the
regular expression pattern regex.
@a = split(/\s*,\s*/, "7, 8, 9");
Sets
@a to ("7", "8", "9").
- push(@name, value) appends a
value (or list of values) onto the end of an array.
- pop(@name) removes and returns the last
element of an array.