in reply to Inline substitution regex
You could use a do block.
$ perl -le ' > $text = q{this text}; > print do{ $text =~ s{this}{that}; $text };' that text $
I hope this is helpful.
Cheers,
JohnGG
Update: Applying the same principle but using map saves some typing.
$ perl -le ' > $text = q{this text}; > print map { s{this}{that}; $_ } $text;' that text $
As others have pointed out though, your code will be clearer to those who follow if you separate the substitution and the print.
|
|---|