http://www.perlmonks.org?node_id=839394


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 (Patriarch) 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?