perl s/this/that/r ==>"Bareword发现运营商的预期"

sds*_*sds 6 perl bareword

Perl文档推荐这个:

$foo = $bar =~ s/this/that/r;
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误:

Bareword found where operator expected near
    "s/this/that/r" (#1)
Run Code Online (Sandbox Code Playgroud)

这是r修饰符特有的,没有代码可以工作.但是,我不想修改$bar.当然,我可以替换

my $foo = $bar =~ s/this/that/r;
Run Code Online (Sandbox Code Playgroud)

my $foo = $bar;
$foo =~ s/this/that/;
Run Code Online (Sandbox Code Playgroud)

有更好的解决方案吗?

bvr*_*bvr 17

正如鲁赫克所写,/r在perl 5.14中是新的.但是,您可以在以前版本的perl中执行此操作:

(my $foo = $bar) =~ s/this/that/;
Run Code Online (Sandbox Code Playgroud)