- When taking a slice, any index can appear anywhere and as many
times as you wish.
- Example:
@First = (1, 2, 3, 4, 5);
@Second = @First[1,2,3,3,2,1];
print "@Second\n";
==> 2 3 4 4 3 2
- Slices can occur on either side of the assignment operator
= .
- Example:
@First = (1, 2, 3, 4, 5);
@First[0, 1, 2, 3, 4] = @First[4, 3, 2, 1, 0];
print "@First\n";
==> 5 4 3 2 1
- Using an index that is beyond the end of the array returns an
undef.
- Assigning to an index that is beyond the end of the array
automatically extends the array to include that value at that new
index, and sets all other new elements between to undef.
- The construct $#ArrayName gives the index
for the last element in array @ArrayName .
- A negative subscript in an array counts backwards from the end of
the array.
- Example:
@First = (1, 2, 3, 4, 5);
@First = @First[-1, -2, -3, -4, -5];
print "@First\n";
==> 5 4 3 2 1