[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Regex replace problem

Peder Axensten wrote:
> I have a hash table where the keys are search patterns and the values are
> the replace string, e.g.:
> $my_hash{"{(.*?)}"}= '$1';
> Futher down I use this in:
> while (($find, $replace)= each (%my_hash)) {
>     $whatever=~ s/$find/$replace/g;
> }
> The $find part works great, but $replace is problematic. It results in
> either the string '$1' literally or the value of $1 when it was put into
> the hash, not when the regex was executed.
> I've tried ='$1', ="$1", ="\$1" etc. and with the 'evaluate' flag with the
> regex but I can't get it to work.

If you always are always replacing with the value of $1, why not use an array
and do this:

#this is psuedo code
@find = (..array of regexes..);
for $find (@find) {
  $whatever =~ s/$find/$1/g;

It looks like that's what you want, based on your message.

Hope that helps,

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org