2009年2月24日星期二

[PerlChina] Re: 求助! 不知道如何描述,正则内插或传递变量给正则的问题

我都是喜欢这样写
my $rr = $1 if $info =~ /aa(.*)bb/;

2009/2/25 buxieyigu <buxieyigu@gmail.com>

谢谢了

On 2月25日, 下午1时33分, agentzh <agen...@gmail.com> wrote:
> 2009/2/25 cnhack TNT <cnhack...@gmail.com>:
>
> > 用 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 讨论组"论坛。
 要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
 要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛

-~----------~----~----~----~------~----~------~--~---

没有评论: