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