in reply to Re: Inline substitution regex
in thread Inline substitution regex

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/ );

Well wrong example, IMHO the misconception is motivated by

print( $num = 3 + 4 );
which prints 7!

Occasionally it's a trap for me, too! 8)

IIRC the binding operator =~ will be changed in Perl6, which thankfully avoids this misleading association!

Cheers Rolf

Replies are listed 'Best First'.
Re^3: Inline substitution regex
by ikegami (Patriarch) on Sep 29, 2009 at 16:12 UTC

    the misconception is motivated by

    It's clearly not generalisable since none of the following doesn't print 7:

    print( 2 + 3 + 4 ); # 9 print( 2 || 3 + 4 ); # 2 print(0+( ($var) = 3 + 4 )); # 1