Actually, the list of values from the RHS is also a list of aliases (to values or to scalar variables, depending on what semantics you want to use at this point).

[The list for the LHS is a list of aliases to variables (not values) but that only makes a difference for aggregate variables (arrays and hashes) -- for assigning from a list of scalar variables to a list of scalar variables, the two lists that get constructed contain identical types of aliases.]

At the time that the code is compiled, Perl tries to determine if it is impossible for the same alias to end up in both lists. If Perl can't determine that that is impossible, then the AAssign op is flagged as "COMMON" (at compile time).

When an AAssign op is executed, if it is flagged as "COMMON", then, before it does the assignments, it first replaces each item in the RHS list (of aliases) with a (non-alias) copy of itself.

$ diff <( perl -MO=Concise -e'($a,$b)=($b,$a)' \ | perl -pe's/0x[\da-f]+/0x/g' ) +\ <( perl -MO=Concise -e'($x,$y)=($b,$a)' \ | perl -pe's/0x[\da-f]+/0x/g' ) -e syntax OK -e syntax OK 4c4 < 9 <2> aassign[t5] vKS/COMMON ->a --- > 9 <2> aassign[t5] vKS ->a 14c14 < 7 <#> gvsv[*a] s ->8 --- > 7 <#> gvsv[*x] s ->8 16c16 < 8 <#> gvsv[*b] s ->9 --- > 8 <#> gvsv[*y] s ->9

- tye        


In reply to Re^2: How swap works (aliases always) by tye
in thread How swap works by srinikar

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.