Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Interpolating backreferences in an eval

by ikegami (Patriarch)
on Feb 11, 2009 at 17:17 UTC ( [id://743113]=note: print w/replies, xml ) Need Help??


in reply to Interpolating backreferences in an eval

'a$1$1c' is a template. You need a template module that understands that format. String::Interpolate should do the trick.
use String::Interpolate qw( ); sub expand { my ($rx, $from, $to) = @_; if ($from =~ $rx) { my $t = String::Interpolate->new(); $t->($to); $t->([ map substr($from, $-[$_], $+[$_] - $-[$_]), 1..$#- ]); print "$t\n"; } }

It's close to Perl code ('"a$1$1c"') so you could convert it to Perl code (the step you are missing) and execute it (eval $code), but that's a very bad approach.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://743113]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-05-27 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found