3 ms·
Yeah, but $#list is better used for writing loops: foreach my $i (0..$#list) { say "$i: $list[$i]"; } For getting the last element from a list you can
by tmtvl 4y ago
Yeah, but $#list is better used for writing loops:
foreach my $i (0..$#list) {
say "$i: $list[$i]";
}
For getting the last element from a list you can just use -1 (and of course further negative numbers work like you would expect, -2 is second to last and so on):
my @last_three = @items[-1, -2, -3];
- melagonster 4y agoyes, I forgot perl have negative index!