Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
more useful options
 
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
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 surveying the Monastery: (8)
As of 2014-04-17 01:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (437 votes), past polls