Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Split at specific spaces

by rubasov (Friar)
on May 11, 2010 at 08:15 UTC ( #839394=note: print w/replies, xml ) Need Help??

in reply to Split at specific spaces

Another way returning the split parts only:
perl -E 'say for split /\S+\s+\S+\s+\S+\K\s+/, "1 2 3 4 5 6 7 8 9"'
Or written shorter:
perl -E 'say for split /(?:\S+\K\s+){3}/, "1 2 3 4 5 6 7 8 9"'

Replies are listed 'Best First'.
Re^2: Split at specific spaces
by BrowserUk (Pope) on May 11, 2010 at 08:36 UTC
    perl -E 'say for split /\S+\s+\S+\s+\S+\K\s+/, "1 2 3 4 5 6 7 8 9"'

    Neat!++ It never crossed my mind that /K would work with split.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: Split at specific spaces
by RedElk (Hermit) on May 11, 2010 at 14:53 UTC

    As a newbie I'm reading and deciphering your response. My reference material doesn't seem to mention "K" anywhere. Can you (or anyone) enlighten me?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://839394]
[Eily]: marto I clearly don't have the thread knowledge to understand the importance of that example
[choroba]: the related discussion on Hacker news is interesting
[choroba]: not so many Perl haters so far

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2017-07-26 14:18 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (396 votes). Check out past polls.