Perlのドキュメントはこれを推奨しています:
$foo = $bar =~ s/this/that/r;
ただし、次のエラーが表示されます。
Bareword found where operator expected near
"s/this/that/r" (#1)
これはr
修飾子に固有のものであり、それがなくてもコードは機能します。しかし、私は変更したくありません$bar
。もちろん交換できます
my $foo = $bar =~ s/this/that/r;
と
my $foo = $bar;
$foo =~ s/this/that/;
より良い解決策はありますか?