3D slice assignment using range operator

I have a 3 dimensional array. I want to set its three elements as follows:

$array[$x][$y][0 .. 2] = (0, 1, 2);

but perl tells me:

Useless use of constant (1) in void context

In the context of an array:

@array[$x][$y][0 .. 2] = (0, 1, 2);

but perl tells me:

syntax error near "] ["

supposedly means that he expects me to give him two indexes and then assign the third dimension as a separate array? However, on this page in the section Example: Assignment Using Array Slicesit is shown that you can assign a slice using the range operator, which says:

@array1[1..3] = @array2[23..25];

How can I assign a slice to such an array, or do I need to assign each index separately?

+4
source share
2

:

@{ $arr[$x][$y] }[ 0 .. 2 ] = (0, 1, 2);
+6

$array[$x][$y][0..2] ; .

, . @arr @{ $arr[$x][$y] }.

, Perl , 3D-. , AoAoA.

:

  • @NAME[LIST]
  • @BLOCK[LIST]
  • @$REF[LIST]
  • EXPR->@[LIST] [1]

:

  • , .
  • @{ $array[$x][$y] }[0..2] = 0..2;
  • my $ref = $array[$x][$y]; @$ref[0..2] = 0..2;
  • $array[$x][$y]->@[0..2] = 0..2; [1]

.


  • Perl 5.24+. Perl 5.20+ use feature qw( postderef );, no warnings qw( experimental::postderef );.
+4

All Articles