in reply to Getting range from N..end with list slice
Maybe your friend is thinking of negative indexes.
$a[-1] # last element $a[-2] # second-last element
This is much older than 5.10. It also works on slices
@a[-2, -1] # second-last and last element
But you have to keep in mind that ".." has nothing to do with slices. If the LHS is greater than the RHS, it returns an empty list.
>perl -E"@a = qw( a b c d e f ); say for @a[4..-1]" >perl -E"@a = qw( a b c d e f ); say for @a[-3..-1]" d e f >perl -E"@a = qw( a b c d e f ); say for @a[-1..-3]" >perl -E"@a = qw( a b c d e f ); say for @a[reverse -3..-1]" f e d >perl -E"@a = qw( a b c d e f ); say for reverse @a[-3..-1]" f e d
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting range from N..end with list slice
by Marshall (Canon) on Nov 28, 2010 at 17:47 UTC | |
by AnomalousMonk (Archbishop) on Nov 28, 2010 at 18:42 UTC | |
by ikegami (Patriarch) on Nov 28, 2010 at 23:37 UTC | |
by AnomalousMonk (Archbishop) on Nov 29, 2010 at 00:26 UTC |