[ In the future, post the code you actually ran rather than making stuff up. Your code does NOT produce the output you specified. In fact, it doesn't run at all. ]
I don't understand why, but it's a common misconception that operators return their left-hand argument. Why you expect the following to print 3?
print( 3 + 4 );
Then why would expect the following to print $text?
print( $text =~ s/this/that/ );
Operators are documented in perlop. s/// is no exception. Search for s/PATTERN/REPLACEMENT/ in the "Regexp Quote-Like Operators" section. It is documented to return the number of substitutions made.
What's the correct way to do it inline?
I'd say it's not correct to do it inline
$text =~ s/this/that/; print $text;
You can manage with the following, but you're complicating your code again.
print( do { $text =~ s/this/that/; $text } );
In reply to Re: Inline substitution regex
by ikegami
in thread Inline substitution regex
by bradcan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |