I have a 3 dimensional array. I want to set three elements of it like this:
$array[$x][$y][0 .. 2] = (0, 1, 2);
but perl tells me:
Useless use of a constant (1) in void context
In array context:
@array[$x][$y][0 .. 2] = (0, 1, 2);
but perl tells me:
syntax error near "]["
presumably meaning that it expects me to give it two indices and then assign to the third dimension as a separate array? However, on this page, under Example: Assignment Using Array Slices
, it suggests that it is possible to assign to a slice using the range operator where it says:
@array1[1..3] = @array2[23..25];
How can I assign to a slice of the array like this, or do I have to assign each index individually?
You need to dereference the inner array:
@{ $arr[$x][$y] }[ 0 .. 2 ] = (0, 1, 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With