解决了 简单说 就是在正则表达式里加入 函数或者执行一些额外操作 可以用 s/$par/ eval $replace/e 解决 详细的请看 perl编程 5.10.3 program parttern
2009/2/25 陈宇迪 <[email protected]> > 你给的这个例子,函数没有参数啊? > 不大懂你的意思,能否说的清楚一些 > > 2009/2/25 buxieyigu <[email protected]>: > > sub regfromvar > > { > > my $str1="requestform"; > > my $str2=$str1; > > my $parttern = "request(form)"; > > my $replacement = '$1'; > > print $str1,"\n"; > > if($str1 =~ s/$parttern/$replacement/igxm) > > { > > print $str1,"\n"; > > } > > > > print $str2,"\n"; > > if($str2 =~ s/$parttern/$1/igxm) > > { > > print $str2,"\n"; > > } > > } > > > > regfromvar(); > > 请看上面的例子,我是想用函数的参数来传递给正则的parttern和replacement,但是不知道如何把 $1 包含在参数中,请问该如何解 > > 决! 谢谢!!! > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
