gnustavo has asked for the wisdom of the Perl Monks concerning the following question:
I'd like it to output two identical lines:#!/usr/bin/perl if ('abc' =~ qr/a(.)c/) { print "a$1$1c", "\n"; } sub expand { my ($rx, $from, $to) = @_; if ($from =~ $rx) { print eval {$to}, "\n"; } } expand(qr/a(.)c/, 'abc', 'a$1$1c');
However, it actually doesn't interpolate the backreferences in the eval and output this:abbc abbc
Any suggestion would be appreciated.abbc a$1$1c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interpolating backreferences in an eval
by ikegami (Patriarch) on Feb 11, 2009 at 17:17 UTC | |
|
Re: Interpolating backreferences in an eval
by gone2015 (Deacon) on Feb 11, 2009 at 17:11 UTC | |
by gnustavo (Novice) on Feb 11, 2009 at 19:05 UTC | |
|
Re: Interpolating backreferences in an eval
by repellent (Priest) on Feb 11, 2009 at 20:17 UTC | |
|
Re: Interpolating backreferences in an eval
by AnomalousMonk (Archbishop) on Feb 12, 2009 at 06:00 UTC | |
|
Re: Interpolating backreferences in an eval
by Anonymous Monk on Feb 11, 2009 at 17:23 UTC | |
by ikegami (Patriarch) on Feb 11, 2009 at 17:28 UTC |