LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2014, 02:03 AM   #1
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Rep: Reputation: Disabled
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.

Last edited by jags1984; 12-10-2014 at 11:08 PM.
 
Old 12-11-2014, 03:21 AM   #2
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Original Poster
Rep: Reputation: Disabled
I solved it.

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


This adds double quote and then evaluates the string.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Perl script for linear interpolation eminempark Programming 11 01-21-2013 12:42 AM
Perl One Liner : Capturing more than one matched regex per line and printing uncle-c Programming 6 01-22-2012 04:16 AM
bash for loop in perl - command interpolation casperdaghost Programming 6 03-19-2010 06:39 AM
perl: how to insert numerical digit immediately after regexp backreference variable? chadwick Programming 8 05-19-2008 12:49 PM
perl script for capturing Memory used by each process Sherlock Programming 3 02-27-2007 10:52 PM


All times are GMT -5. The time now is 08:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration