Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 chanting in the Monastery: (4)
As of 2016-06-26 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (328 votes). Check out past polls.