On 11/25/2006 06:40 AM, perl pra wrote:
hi Gurus,

I have a problem to replace strings of file thru perl script.


Here is the problem in detail...


I have a text file  some thing like this..


PROJ_FOLER=C:\Proj
PROJ_LOGS=C:\PROJ\LOGS


I have same line in config file some thing like this.


PROJ_FOLDER=D:\Proj
PROJ_LOGS=D:\PROJ\LOGS.


Now i read variables from text file split them like this

my ($key,$val)= $line =~ /^(\w+)=(.+)$/mg ;

and place both in a varaible $rep_line="$key=$val";

and search in the config file with $key (which has PROJ_FOLDER) and get to
the result to $line.

Now i will replace $line with $rep_line using

perl -i -p -e 's/$line/$rep_line/g'  $file;

Here is the code i have written...

BEGIN________

#!/usr/bin/perl

Missing:
use strict;
use warnings;

Modify your program to work with them.

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;}


Inline editing, on my platform, results in the original file being renamed and eventually deleted. Why are you creating a separate perl process to modify a file you already have open?


       }
                                 }
  close(FH);
END _____________

if i run the script I am getting the following errror..


Can't find string terminator "'" anywhere before EOF at -e line 1.
Can't find string terminator "'" anywhere before EOF at -e line 1.
Can't find string terminator "'" anywhere before EOF at -e line 1.
Can't find string terminator "'" anywhere before EOF at -e line 1.
Can't find string terminator "'" anywhere before EOF at -e line 1.
Can't find string terminator "'" anywhere before EOF at -e line 1.
Can't find string terminator "'" anywhere before EOF at -e line 1.

What am i doing wrong?


My eyes are too old to see a stray ' somewhere in a program. My guess is that it has something to do with the call to system (which shouldn't be called anyway).

Please help me on this..


Thanks in Advance

PP..


HTH


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to