http://www.perlmonks.org?node_id=369539


in reply to Re: Quantum Weirdness and the Increment Operator
in thread Quantum Weirdness and the Increment Operator

Yes.

Part of what surprised me was that "return" gave me back a copy, so my "noop" subroutine should actually be called "copy".

sub noop { X::is_x( $_[0] ); # ok return $_[0]; } X::is_x( noop($x) ); # not_ok
Update

The plot thickens.

I see over on Aliasing and return, how does return work? a discussion of just this issue, with a suggestion by japhy to use lvalue subs.

A quick test shows that one can indeed return $x itself this way - but the increment expression is still altered by a call to this kind of subroutine, too.

sub noop_lval :lvalue { $_[0] } X:is_x( noop_lval($x) ); # ok ! $m=20; print noop_lval(++$m) + $m++; # 42 (still) $m=20; (++$m) + $m++; # 43
So I guess the copy that "return" makes isn't the whole issue.