DavidSzczesniak
12/7/2017 - 10:29 AM

Accessing array elements (SLICE)

# Swap parts of the array 
$fred = (7, 8, 9);
($fred[0], $fred[1]) = ($fred[1], $fred[0]); # swapped first two elements

# Accessing a list of elements from the same array
@fred[0, 1]; # same as (@fred[0], @fred[1])
@fred[0, 1] = @fred[1, 0]; # swaps the first two elements
@fred[0, 1, 2] = @fred[1, 1, 1]; # make first three elements just like the second
@fred[1, 2] = (9, 10); # change last two values to 9 and 10