> $pattern = 'search_for(but_preserve)';
> $replace = 'replace_with $1';
> s/$pattern/$replace/;
The // operator interpolates as a double quoted string, but does not
interpolate a second time, so the '$1' will be interpreted literally. I
believe if you add the /e option, it will work as expected:
s/$pattern/$replace/e;
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
> From: "Pascal Oberndoerfer" <[EMAIL PROTECTED]>
> Date: Thu, 18 Oct 2001 19:00:38 +0200
> To: [EMAIL PROTECTED]
> Subject: [MacPerl] Variables and grouping in RegExs
>
> Hello.
>
> I got into trouble using grouping and variables in regular expressions.
>
> Given this scenario:
>
> s/search_for(but_preserve)/replace_with $1/;
>
> I can also do:
>
> $pattern = 'search_for(but_preserve)';
> $replace = 'replace_with';
> s/$pattern/$replace $1/;
>
> But I am unable to do:
>
> $pattern = 'search_for(but_preserve)';
> $replace = 'replace_with $1';
> s/$pattern/$replace/;
>
>
> It would be very helpful if I could to this as the grouping in the
> "$pattern" varies as well as the placement of the corresponding
> variables $1, $2, ...
>
> I tried to do it with eval() -- without any success. Does eval() make
> any sense here at all?
>
> Any help would be very much appreciated!
>
> TIA
>
> Pascal
>