Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Split words

by cheekuperl (Monk)
on Jul 11, 2012 at 14:45 UTC ( #981136=note: print w/ replies, xml ) Need Help??


in reply to Split words

while($line=<DATA>) { if($line=~/(.*)(monks)(.*)/) { print "\n$1\n$2\n$3"; } } __DATA__ perl monks wisdom monks perl wisdom


Comment on Re: Split words
Download Code
Re^2: Split words
by ww (Bishop) on Jul 11, 2012 at 15:18 UTC
    fails when the split word, monks, is repeated:
    __DATA__ perl monks wisdom monks perl wisdom perl perl monks monks wisdom perl perl monks monks monkly wisdom
      Nice observation!
      However, for repeating "monks" all we need is this:
      while($line=<DATA>) { while($line=~m/monks/g) { print "\n==>$`\nmonks\n$'"; } }
      Now I've assumed prefix of "monks" means whatever precedes "monks" in the string (even if it contains previous "monks") Same goes for postfix.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-08-20 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (125 votes), past polls