It takes a little extra work, but it is certainly do-able...
The double /ee is needed. The first /e sub's in the value of $rpl. The second /e evaluates that and DWIM's.#!/usr/bin/perl -w use strict; my $find = 'proof(\S+)'; my $rpl = '"read$1"'; my $text = 'proofing is proof it needed to be proofed'; if ($text =~ s/$find/$rpl/ee) { print "1st replacement made:\n\t$text\n"; }
The nested quotes are needed in defining $rpl because without the inner double-quotes, the second /e fails. Another way to do that bit (and this may help in understanding) would be: my $rpl = '"read" . $1'; You have to get both the quoting and the /ee right for the thing to work as intended.
HTH
------------------------------------------------------------
"Perl is a mess
and that's good because the
problem space is also a mess." - Larry Wall
In reply to Re: Re: evaluating $1 in a replace string
by dvergin
in thread evaluating $1 in a replace string
by Oaks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |