Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.


In reply to Re^5: Why Perl boolean expression sometimes treated as lvalue? by ikegami
in thread Why Perl boolean expression sometimes treated as lvalue? by vsespb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (8)
    As of 2014-04-18 12:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (466 votes), past polls