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


in reply to Re^4: Why Perl boolean expression sometimes treated as lvalue?
in thread Why Perl boolean expression sometimes treated as lvalue?

Oh, ikegami says it doesn't return a copy (why would it) -- who asked about a copy ?

He asked why the sub changed it, which is the same as asking why a copy wasn't made (given that he knows about argument aliasing). This was my point.

( $blah && $foo ) = foo(); is illegal Where is this documented?

It's not. Nowhere says it say the LHS of an assignment cannot be an arbitrary expression beyond "assignment operators work as in C", but it makes no sense to accept arbitrary expressions. ("abc" = 3;?) Those that are accepted are called "lvalue" expressions. (This isn't mentioned. Patches welcome.)

That said, things that return lvalues are documented to do so in their respective documentation:

Why is it illegal?

Can't say for sure, but it's traditional not too allow much more than a variable on the LHS of assignments. In fact, Perl does allow the similar $x ? $x : $y to be used as an lvalue, and we've all seen the questions asking "why f() ? $x=3 : $y=4; doesn't work?" that result from that decision.

Replies are listed 'Best First'.
Re^6: Why Perl boolean expression sometimes treated as lvalue?
by ikegami (Patriarch) on Feb 11, 2013 at 22:23 UTC
    I forgot my, our and local. local isn't documented to be usable as an lvalue.