Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Last index use in array slice

by ColonelPanic (Friar)
on Dec 03, 2012 at 13:29 UTC ( #1006877=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Last index use in array slice
in thread Last index use in array slice

Yeah, I thought of that one, but ultimately didn't use it because, as you mentioned, it doesn't work well with an arbitrary starting index.

You could do something like this:

my $str = "discard\ndiscard\nkeep1\nkeep2"; my $index = 2; my @arr = grep {$index-- <= 0} split "\n", $str;


When's the last time you used duct tape on a duct? --Larry Wall


Comment on Re^3: Last index use in array slice
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-12-29 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (192 votes), past polls