philkime has asked for the wisdom of the Perl Monks concerning the following question:
I would like to see "AZBC", for example but the $1 is interpreted as literal, as I suppose I should expect. Is there some way to have the replacement interpret $1, $2 etc?$string = 'ABC'; $search = qr/^(A)/; $replace = '$1Z'; $string = s/$search/$replace/g; say $string;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interpolate into replacement with s//?
by ikegami (Patriarch) on Nov 09, 2011 at 20:43 UTC | |
by tchrist (Pilgrim) on Nov 09, 2011 at 20:54 UTC | |
by philkime (Beadle) on Nov 09, 2011 at 21:18 UTC | |
by ikegami (Patriarch) on Nov 09, 2011 at 21:31 UTC | |
by philkime (Beadle) on Nov 10, 2011 at 09:14 UTC | |
| |
|
Re: Interpolate into replacement with s//?
by SuicideJunkie (Vicar) on Nov 09, 2011 at 20:40 UTC |