用 eval 是正解 :-)

2009/2/25 Michael Zeng <[email protected]>

>  没看懂你在干啥,能举个例子么
>
> 感觉这样写 $1 应该不好
>
>
>
> On 2/25/09, buxieyigu <[email protected]> wrote:
>>
>> sub regfromvar
>> {
>>        my $str1="requestform";
>>        my $str2=$str1;
>>        my $parttern = "request(form)";
>>        my $replacement = '$1';
>>        print $str1,"\n";
>>        my $suc;
>>        eval '$suc=$str1 =~ s/'.$parttern.'/'.$replacement.'/igxm';
>>        if($suc)
>>        {
>>                        print $str1,"\n";
>>        }
>>
>>        print $str2,"\n";
>>        if($str2 =~ s/$parttern/$1/igxm)
>>        {
>>                        print $str2,"\n";
>>        }
>> }
>>
>> regfromvar();
>>
>> 这样好像能解决问题,但是感觉不太对劲,有没有更标准的方法,难道正则不提供 $1 的转换么,传给他字符串就只能当作字符串处理。
>> >>
>>

--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。
 要在此论坛发帖,请发电子邮件到 [email protected]
 要退订此论坛,请发邮件至 [email protected]
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---

回复