in reply to Re: evaluating $1 in a replace string
in thread evaluating $1 in a replace string
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: evaluating $1 in a replace string
by Fletch (Bishop) on Jul 08, 2002 at 11:41 UTC | |
|
Re: Re: Re: evaluating $1 in a replace string
by Oaks (Novice) on Jul 08, 2002 at 06:24 UTC |