Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: find & replace a string in perl

by mertserger (Curate)
on Nov 25, 2010 at 10:10 UTC ( #873611=note: print w/replies, xml ) Need Help??


in reply to Re^2: find & replace a string in perl
in thread find & replace a string in perl

The code:
if( $line =~ s/\btest\b/^\#/ig ) { print "$line\n"; }
is definately wrong as Corion has been saying.
The bit in brackets after the "if" should be a test with a Boolean answer, whereas you've got a substitute command instead. Also if the substitution ever worked you would not be adding a hash in front of the line but replacing "test" with "^#" so your example line "see/for/test " would become "see/for/^#". You want something like:
if( $line =~ m/test/ ) { $line = "#" . $line; print "$line\n"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-05-26 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?