Formatting output after search and replace
- From: sreevidhyas@xxxxxxxxx (Melody)
- Date: Tue, 29 Apr 2008 15:06:48 -0700 (PDT)
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
.
- Follow-Ups:
- Re: Formatting output after search and replace
- From: Chas. Owens
- Re: Formatting output after search and replace
- Prev by Date: Re: perl -MCPAN -e shell failed
- Next by Date: Re: removing duplicates
- Previous by thread: Re: removing duplicates
- Next by thread: Re: Formatting output after search and replace
- Index(es):
Relevant Pages
|
|