Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to substitute all the words before a certain word in the middle of a line?

by Ted Nitz (Chaplain)
on Jul 12, 2000 at 20:01 UTC ( #22213=note: print w/ replies, xml ) Need Help??


in reply to How to substitute all the words before a certain word in the middle of a line?

I'm assuming that there should have been line breaks in the sample data, so that each sentince was on a separate line. Also, this code will match everything before the first occurance of the trigger word (nice in this case). You can replace <DATA> with another filehandle or with <> depending upon where you want to get the lines.

my $triggerword = "nice"; my $replacement = "A "; while(<DATA>){ s/^.*?(?=$triggerword)/$replacement/o; print; } __DATA__ This is a nice weather. He is a nice guy. We have some nice food in our dinner.


Comment on Re: How to substitute all the words before a certain word in the middle of a line?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-08-28 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (256 votes), past polls