user-pic

issues using matching variable $1,$2,....

Vote 1 Vote
my $v = q/There are 2 boys/; my $regx = '\b(\d+)\b'; my $str = q/$1 of/; # I try to have $1 in a variable and then use the variable in s/// $v =~ s/$regx/$str/g; print $1,"\n"; # print out $1 value print "$v"; The output is as below 3 There are $1 of 10 boys Then I use "$v =~ s/$regx/$str/gee" instead, it output; Bareword found where operator expected at (eval 1) line 1, near "$1 of" (Missing operator before of?) Number found where operator expected at (eval 1) line 1, near "of 10" (Do you need to predeclare of?) 3 There are boys It seems there are no way to let the $1 to be interpolated in this case
1

Add a Reply

Forum Groups

Good Perl Books

Perl 學習手札

作者:簡信昌

Perl 學習手札 , 一本优秀的中文Perl在线学习资料。

Perl 程序讨论区

12 50

Last Topic: [注意]本区文章归档区 by 路杨 on Oct 16, 2006

事物处理及其他

113 1410

Last Topic: 踩个脚印 by 眼睛oo on Dec 4, 2010

测试私密区

测试私密区

18 88

Notice: 用于测试程序或者不可告人之秘密。不要问我要密码哦。。[此为原LB_ES论坛系统保留项,只限原有权限朋友进入,不再接受注册]

OpenID accepted here Learn more about OpenID