in reply to Array slice out of order

Heheh ... in C, that would be called "undefined behaviour". Any behaviour, including formatting of the author's hard disk (even if not running on the author's machine), is allowed.

It all depends on the order that perl evaluates the expression. It looks like perl evaluates the subscripts from right to left in this case, so it evaluates the $i++ (incrementing i after putting a zero there), and then evaluates the $i (putting the newly-incremented value of one there), and then splices. Neat!

Update:Slight clarification (emphasised) (thanks dragonchild and cog)

Replies are listed 'Best First'.
Re^2: Array slice out of order
by dragonchild (Archbishop) on Feb 03, 2005 at 18:50 UTC
    Actually, it doesn't evaluate right-to-left for an arbitrary reason.

    The complete expression is evaluated inside-to-outside. The innermost expression is [$i, $i++]. The comma operator, within a list context (which the [] provides), evaluates from right-to-left. (This is different from a scalar context where it evaluates the LHS, discards the value, then evaluates the RHS.)

    It's not clearly spelled out, but you can look at p.108 (for the comma operator) and p.109 (for list contexts in general) of the 3rd ed. Camel.

    Update: Roy Johnson's answer is much better than mine.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re^2: Array slice out of order
by halley (Prior) on Feb 03, 2005 at 18:33 UTC
Re^2: Array slice out of order
by cog (Parson) on Feb 03, 2005 at 18:54 UTC
    It still prints 'ab' for print @m[$i++,$i], so it doesn't seem a case of "right to left evaluation" to me...