Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://839394]
help
Chatterbox?
[shmem]: hmm.. which makes emerge the question: is there a way to attach a subroutine to a variable, which is run as soon as that variable changes?
[moritz]: through a tie?
[shmem]: moritz: of course!
shmem slaps forehead m(
[shmem]: consider, then, @CBMonks as a tied variable which triggers withdrawing empty cups and serving new ones

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-04-24 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (439 votes). Check out past polls.