Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Why Perl boolean expression sometimes treated as lvalue?

by ikegami (Pope)
on Feb 11, 2013 at 04:31 UTC ( #1018092=note: print w/ replies, xml ) Need Help??


in reply to Why Perl boolean expression sometimes treated as lvalue?

Quite simply:

  • $y always returns the scalar, not a copy of it.
  • && always returns the scalar its LHS returned or the scalar(s) its RHS returned, not a copy of it.

That's it. Why isn't it documented that they don't make a copy in rvalue context? Why would it.

If you wanted to explicitly copy the scalar, you could do a( 0+( $x && $y ) ). Then, $_[0] = 3; will modify the anonymous scalar the addition constructed.


Comment on Re: Why Perl boolean expression sometimes treated as lvalue?
Select or Download Code
Replies are listed 'Best First'.
Re^2: Why Perl boolean expression sometimes treated as lvalue?
by Anonymous Monk on Feb 11, 2013 at 04:58 UTC
    You're missing the point

      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 ?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (18)
As of 2015-07-30 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls