Re: Problem with replacing string in file



In article
<8070ef410611250440h77c537c0k8c5d36e5fa10fcab@xxxxxxxxxxxxxx>,
perlpra@xxxxxxxxx (Perl Pra) wrote:
....

#!/usr/bin/perl
my $config_path="E:/MessageArchive/WorkArea/config.txt";
$file="E:/temp/FT/config/FTMessageArchive.configd";
open FH, "$config_path";

while ($line=<FH>)
{


my ($key,$val)= $line =~ /^(\w+)=(.+)$/mg ;
$repline="$key=$val";
open $LOGFILE, '<', $file;
while ($line1 = <$LOGFILE> )
{
if ($line1 =~ m/$key/){ system("perl -i.bak -p -e
's/$line1/$repline/g' $file");close $LOGFILE;last;}

}
}
close(FH);
END _____________
....

Interesting script. I don't think I would have thought up this way to
solve the problem. I think the error may be caused by the $repline
variable - it probably has metacharacters in it that have special
meaning to reg. exp., so they should be "escaped" with "\";

I will try writing a short script "my way" and post it soon.

Boyd
.



Relevant Pages