It's not the issue with order of evaluation, but, looks like, some aliasing is going on, when same variable is used on left and right sides, and modified on the right side.

I was trying to be "clever", slicing array and sliding window at the same time, like this:

>perl -wE "@a=1..9; $i=0; say @a[$i..($i+=3)-1] while $i<@a #1"

No ouput.. Blank lines, but not the output I expected (123\n456\n789\n). Then further:

>perl -wE "$i=1; say for $i..$i++ #2" >perl -wE "$i=1; say for $i..++$i #3" 2 >perl -wE "$i=1; say for do{$i}..do{$i++} #4" >perl -wE "$i=1; say for do{say 'hi!';$i}..do{say 'bye!';$i++} #5" hi! bye! 1 >perl -wE "$i=1; say for do{$i?$i:($i+1)}..$i++ #6" >perl -wE "$i=1; say for do{$i?$i:($i++)}..$i++ #7" 1

Maybe I'm wrong and it's not a bug, and there's some logical explanation? Last examples are frightening.

Edit. Corrected the output I expected (thanks, Marshall). Added line numbers to one-liners to refer to them.

Edit 2. But what about the do returning either value (#5, #7) or alias (#4, #6)?

do:

do BLOCK

...Returns the value of the last command in the sequence of commands indicated by BLOCK.

In reply to Strange aliasing(?) when modifying variable in range operator by vr

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.