Formatting output after search and replace



I have 2 files one has the input and the other has data that will
replace specific string in file 1

eg
----

File 1
---------
Text| to be replaced
Text| to be replaced
Text| to be replaced
Text| to be replaced
Text| to be replaced

File 2
---------
replaced1
replaced2
replaced3

Output
----------
Text|replaced
Text|replaced
Text|replaced
Text|replaced
Text|replaced

I have a pgm that works but the output looks like

text|replaced1

text|replaced2

text|replaced3
text|replaced1

text|replaced2

Here is the code
--------------------------

#!/usr/bin/perl
use warnings;
use strict;

my @array;
my @replacearray;

open FHR,'<',"repl.txt";
open OUT,'>>',"output.txt";
open IN,'<',"input.txt";
@replacearray=<FHR>;
@array=<IN>;

for my $i(0..$#array)
{
$array[$i]=~s/to be replaced/$replacearray[0]/gi;
push @replacearray, shift @replacearray;
}
my @result=grep(/[^\$]/,@array);
print OUT @result;


Can anyone point out to me what i am doing wrong??Thanks

.



Relevant Pages

  • Re: Batch Replace function for Large strings
    ... If InStr(1, InputString, FindArray(i)) Then ... > String processing in VBA is very slow when strings are large. ... > ReplaceArray As Variant, Optional MatchCase As Boolean = False) As ... > Exit Function ...
    (microsoft.public.excel.programming)
  • Formatting output after search and replace
    ... replace specific string in file 1 ... push @replacearray, shift @replacearray; ...
    (perl.beginners)