heeru has asked for the wisdom of the Perl Monks concerning the following question:
Hi Experts,
I have the following code (which parses through a file) looking for particular text.
This works perfectly fine and replaces all occurrences in the file correctly. Issue here is, the third time this text appears, it appears after a line, lets say, <bindname>abcde<\/bindname>. I do not want the occurrence to change in this case. So how can I include this in my code? Help appreciated. Thanks !$fileName = shift; open(HND, $fileName) or die "Can't open $fileName: $!"; @fileArr = <HND>; close(HND); foreach my $line ( @fileArr ) { $line =~ s/<bindpass>welcome<\/bindpass>/<bindpass>Welcome1<\/ +bindpass>/g; } open(HND, ">$fileName") or die "Cant open for writing $fileName: $!" +; print HND @fileArr; close(HND);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Search and replace query
by moritz (Cardinal) on Aug 26, 2011 at 10:08 UTC | |
Re: Search and replace query
by cdarke (Prior) on Aug 26, 2011 at 10:23 UTC | |
by pvaldes (Chaplain) on Aug 26, 2011 at 11:18 UTC | |
Re: Search and replace query
by RichardK (Parson) on Aug 26, 2011 at 11:58 UTC | |
by Lotus1 (Vicar) on Aug 26, 2011 at 12:50 UTC | |
by Anonymous Monk on Aug 26, 2011 at 12:54 UTC | |
Re: Search and replace query
by Anonymous Monk on Aug 26, 2011 at 13:08 UTC |
Back to
Seekers of Perl Wisdom