Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

Rep: Reputation: Disabled
String interpolation while using backreference and capturing in perl.

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



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-11-2014 at 12:08 AM.
Old 12-11-2014, 04:21 AM   #2
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.


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 01:42 AM
Perl One Liner : Capturing more than one matched regex per line and printing uncle-c Programming 6 01-22-2012 05:16 AM
bash for loop in perl - command interpolation casperdaghost Programming 6 03-19-2010 07:39 AM
perl: how to insert numerical digit immediately after regexp backreference variable? chadwick Programming 8 05-19-2008 01:49 PM
perl script for capturing Memory used by each process Sherlock Programming 3 02-27-2007 11:52 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:38 PM.

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