LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   String interpolation while using backreference and capturing in perl. (https://www.linuxquestions.org/questions/linux-newbie-8/string-interpolation-while-using-backreference-and-capturing-in-perl-4175527861/)

jags1984 12-10-2014 02:03 AM

String interpolation while using backreference and capturing in perl.
 
mycode.txt:
Code:

my $PATH="/home/test.txt";
my $Filename2="/home/read.txt";

open(TEST, "< $PATH");
my @array = <TEST>;
my $line;

foreach $line (@array)
{

        # ***************This line works !!
        open(FH, "< $Filename2");
        my @srcstr = <FH>;
        chomp @srcstr;

        if ( $line =~ /$srcstr[0]/ ) {
                print "Matched string= $&";
                print "Changed string= $srcstr[1]\n ";
        }

}



read.txt:
Code:

fnOpenLog\(([\w&\*\s]+)\,([\w&\*\s]+)\,([\w&\*\s]+)\)
"fopen($2,$1)"


I am not able to print the captured string in "Changed string".
Interpolation is not happening while reading from file.

jags1984 12-11-2014 03:21 AM

I solved it.

The changed string must be assigned as, eval(qq/$srcstr[1]/).


This adds double quote and then evaluates the string.


All times are GMT -5. The time now is 09:01 AM.