use List::Util qw(max); @last_n = @source[max(0, @source - $n) .. $#source];
Update: Fixed offby1-error pointed out by AnomalousMonk++
In reply to Re: What’s the best way to get the last N elements of a Perl array?
by moritz
in thread What’s the best way to get the last N elements of a Perl array?
by vinoth.ree
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |