in reply to Slicing an array variable with a -1 or any negative number doesn't work

Slicing with negative numbers does work. What doesn't however is 0..-1, as the .. operator only counts up. So (0..-1) is an empty list.

@{$row}[0,-1] will work. Or if you want a list of negative number, you can make one with map: @{$row}[map -$_, 0..2]

Edit: oh I thought you wanted 0..-2 to mean (0, -1, -2), but maybe hippo's interpretation is what you wanted: from the first element to the one before the last. In which case you have to use $#{$row}, the index of the last element as proposed by hippo

Replies are listed 'Best First'.
Re^2: Slicing an array variable with a -1 or any negative number doesn't work
by igoryonya (Pilgrim) on Nov 29, 2017 at 11:29 UTC
    Ok, I got it.
    -1 or other -x (negative numbers) in slices, can only work with commas, but not with ..
    I see.

    Thank You.

      -1 or other -x (negative numbers) in slices, can only work with commas, but not with ..

      Nope. The point is that ".." counts up. These work:

      @letters = ('a'..'z'); say for @letters[-5..-1]; say for @letters[reverse(-1..0)];
      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'