in reply to $1 in variable regex replacement string
The reason it doesn't work is (of course) found in the Camel Book:
The right side of the substitution (between the second and third slashes) is mostly a funny kind of double-quoted string, which is why you can interpolate variables there, including backreference variables. (p.41)
As you know you only get one level of interpolation in Perl, i.e. your $repl gets replaced by whatever its value is at that moment and then interpolation stops and hands the regex to the regex-engine, which will find a literal $1 and not the value inside the backreference variable $1 you wished for.
The only solution is through the /e modifier als already pointed out.
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: $1 in variable regex replacement string
by dvergin (Monsignor) on Feb 12, 2003 at 20:35 UTC | |
by CountZero (Bishop) on Feb 13, 2003 at 07:01 UTC |