Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What I want to do is to do a find the exact match & replace.<String> <This is the firstline> <This is the secondline>
My desired output.open (FH,"text.txt"); @lines=<FH>; @patterns = qw/<string> line secondline/; @replace = qw/'<REPLACED>' 'line_R' 'secondline_R'/; foreach $line (@lines){ chomp $line; for ($i=0;$i<=2;$i++){ if ($line =~ /\B$patterns[$i]\B/i){ $line =~ s/$patterns[$i]/$replace[$i]/i; push @repd,$line; } } } foreach $line (@repd){ print "$line\n"; }
But what i am getting as output'<REPLACED>' //<String>->'<REPLACED>' <This is the 'secondline_R'> // secondline->'secondline_R'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: word & non-word boundries
by almut (Canon) on Mar 03, 2010 at 11:27 UTC |