Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Why Perl boolean expression sometimes treated as lvalue?

by Anonymous Monk
on Feb 11, 2013 at 04:58 UTC ( #1018095=note: print w/ replies, xml ) Need Help??

Comment on Re^2: Why Perl boolean expression sometimes treated as lvalue?
Re^3: Why Perl boolean expression sometimes treated as lvalue?
by ikegami (Pope) on Feb 11, 2013 at 05:50 UTC

    If so, your message does not help. Please clarify the question if you think I didn't understand it.

      If so, your message does not help. Please clarify the question if you think I didn't understand it.

      Consider that you didn't miss the point -- in what way does your reply constitute an answer or an explanation?

      foo( $blah && $foo ); works to alias $foo

      $ref = \($blah && $foo); works to reference $foo

      ( $blah && $foo ) = foo(); is illegal

      Where is this documented? Why is it illegal?

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

        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:

        • The assignment operators return an lvalue;
        • susbtr, vec, pos and keys can return an lvalue; and
        • lvalue subs return an lvalue.

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018095]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-09-22 23:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (208 votes), past polls