[prev] [index] [next]

Arrays (Lists) (cont)

Arrays do not need to be declared, and they grow and shrink as needed.

"Missing" elements are interpolated, e.g.

$abc[0] = "abc";  $abc[2] = "xyz";
# reference to $abc[1] returns ""

Can assign to a whole array; can assign from a whole array, e.g.

@numbers = (4, 12, 5, 7, 2, 9);
($a, $b, $c, $d) = @numbers;

Since assignment of list elements happens in parallel ...

($x, $y) = ($y, $x);   # swaps values of $x, $y