XP is just a number | |
PerlMonks |
Re: What’s the best way to get the last N elements of a Perl array?by linuxer (Curate) |
on Apr 20, 2009 at 11:29 UTC ( [id://758676]=note: print w/replies, xml ) | Need Help?? |
If undef is no valid entry in your array, you could use your solution and grep the defined values from your slice result.
Update: As svenXY mentioned: my solution does not work! :o(
Can someone please enlighten me, what's the problem with my attempt? 2nd Update: During my research I found an explanation in Modification of non-creatable array value attempted (it's a slightly other topic, but at least the same error message) and grep's perldoc. I came to the conclusion, that the error is thrown, because grep tries to alias the list values; and this fails for not existent array elements.
In Section
Seekers of Perl Wisdom
|
|