Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: What’s the best way to get the last N elements of a Perl array?

by linuxer (Curate)
on Apr 20, 2009 at 11:26 UTC ( #758674=note: print w/ replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://758674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2016-08-27 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (379 votes). Check out past polls.