But why [is aliasing] also involved when composing a list?

Most likely because a list can be used like:

( $c, $d ) = ( 1, 2 )

But I'm just guessing. There are usually some subtle implementation details involved. There is often quite complicated history involved as well.

Where is documented?

The types of things that are more likely to change based on changes to Perl having to do with esoteric implementation details, especially optimizations, are often bad things to try to document, IMHO. In any case, I doubt this is documented.

Modifying a variable in the same statement where you use the variable is just something to avoid. Knowing what it does in this version of Perl doesn't mean it will continue to do that in another version of Perl. Having a rough understanding of why it does what it currently does, tends to not be very reliable in allowing even a rather gifted Perl programmer to avoid getting rather different behavior from a very similar construct (and thus being surprised and perhaps resulting in a bug in the code being written).

C is nice in having a standard that pretty clearly lays out this type of thing as officially "undefined behavior". This is a very useful way to push back against clever programers' natural tendency to, from time to time, want to continue to use some overly clever construct.

That C rule and definition don't really apply to Perl. But the motivation for them very much applies to this type of thing in Perl. Trying to tie down exactly how something like this should behave just leads to complex and problematic tying of the hands of the implementers and fixers of bugs in Perl.

So just don't do this type of thing. And don't get too obsessed about why it does what it does. It is more important to understand why it is a construct that you shouldn't be writing. If you've got that down, then you can casually try to better understand what is going on in an attempt to better understand some aspects of Perl. But beware that this might put you at risk of, perhaps unintentionally, relying upon these new assumptions. Best to keep such conclusions you come to marked as guesses or at least vague and not something to rely upon.

- tye        


In reply to Re^4: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ? ("undefined") by tye
in thread Why does the first $c evaluate to the incremented value in [$c, $c += $_] ? by smls

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.