http://www.perlmonks.org?node_id=758674


in reply to Re: What’s the best way to get the last N elements of a Perl array?
in thread What’s the best way to get the last N elements of a Perl array?

Beware: What does that solution do, if $n > @source?

See:
$ perl -le '@a = 1..3; @b = @a[(@a-5)..$#a]; print "<$_>" for @b;' <2> <3> <1> <2> <3>

Replies are listed 'Best First'.
Re^3: What’s the best way to get the last N elements of a Perl array?
by Utilitarian (Vicar) on Apr 20, 2009 at 13:09 UTC
    @last_n=@source[(@source-$n)..$#source]if ($n<=@scource);
    Would be the solution there I guess