M
MJS
I have a hard time matching and replacing this pattern. It works fine
for single line but when I want to replace multiple line pattern, it
doesn't seem to work. I spend a lot of time on faq but I guess I m not
smart enough to figure out where I am going wrong. I couldn't do it
using the regular exp. so I tried doing it using Tie::File.
Please help me with this.
============================
use Tie::File;
use strict;
use warnings;
# tie @array to filename using Tie::File
tie my @array, 'Tie::File', 'result.txt' or die "Cannot open
result.txt:$!";
while(<result.txt>){
for(@array) {
my $pattern = "The text
to be
searched
in differnt
lines inclunding white lines and indentation";
my $replace = " The replacing
text
also in
multiple lines
including indentation and white lines ";
s/$pattern/$replace/;
}
}
untie @array;
==============================
for single line but when I want to replace multiple line pattern, it
doesn't seem to work. I spend a lot of time on faq but I guess I m not
smart enough to figure out where I am going wrong. I couldn't do it
using the regular exp. so I tried doing it using Tie::File.
Please help me with this.
============================
use Tie::File;
use strict;
use warnings;
# tie @array to filename using Tie::File
tie my @array, 'Tie::File', 'result.txt' or die "Cannot open
result.txt:$!";
while(<result.txt>){
for(@array) {
my $pattern = "The text
to be
searched
in differnt
lines inclunding white lines and indentation";
my $replace = " The replacing
text
also in
multiple lines
including indentation and white lines ";
s/$pattern/$replace/;
}
}
untie @array;
==============================