Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: find & replace a string in perl

by Corion (Patriarch)
on Nov 25, 2010 at 07:57 UTC ( #873593=note: print w/replies, xml ) Need Help??


in reply to find & replace a string in perl

s/test/^\#/g

This does not do what you think it does. Try this substitution on its own and think about what you see. Good example data would be

hello test foo thisisjustatest test1 test2 test3

Hint: The right hand side of a regular expression is not magic, it is just a string.

Replies are listed 'Best First'.
Re^2: find & replace a string in perl
by iefbr14 (Initiate) on Nov 25, 2010 at 15:22 UTC
    i'd try
    s/^(.*?)test(.*)$/"#$1"."test$2"/e

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2022-08-10 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?