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 | |
by shmem (Chancellor) on Nov 29, 2017 at 12:47 UTC |