我都是喜欢这样写 my $rr = $1 if $info =~ /aa(.*)bb/; 2009/2/25 buxieyigu <[email protected]>
> > 谢谢了 > > On 2月25日, 下午1时33分, agentzh <[email protected]> wrote: > > 2009/2/25 cnhack TNT <[email protected]>: > > > > > 用 eval 是正解 :-) > > > > 是啊,eval 是正解: > > > > sub regfromvar > > { > > my $str1="requestform"; > > my $str2=$str1; > > my $parttern = "request(form)"; > > my $replacement = '$1'; > > print $str1,"\n"; > > if($str1 =~ s/$parttern/eval $replacement/eigxm) > > { > > print $str1,"\n"; > > } > > > > print $str2,"\n"; > > if($str2 =~ s/$parttern/$1/igxm) > > { > > print $str2,"\n"; > > } > > > > } > > > > regfromvar(); > > > > 输出是期望的了: > > > > requestform > > form > > requestform > > form > > > > 不过如果 $replacement 来自外部的话,要小心注入哦。。。呵呵。。。 > > > > Cheers, > > -agentzh > > -- blog - http://hi.baidu.com/smallfish7788 --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
