in reply to Re: Unexpected behaviour with constant lists
in thread Unexpected behavior of '..' lists

I'm not exactly sure what you mean by counting loop. Are you saying that

foreach $x (expr1..expr2) { blah }

is implemented more like

for ($y=expr1 ; $y<expr2 ; $y++) { $x=$y; blah }

internally ?

Replies are listed 'Best First'.
Re^3: Unexpected behaviour with constant lists
by ikegami (Patriarch) on Jul 20, 2006 at 18:43 UTC
    Indeed. It's probably implemented identically to for (my $x=expr1 ; $x<=expr2 ; $x++) { blah }

    Update: Changed "<" to "<=".

      It's not implemented like that at all. There's a specific set of ops meant for the range operator. It's much better than the longhand for(;;) which would be lots of more ops to dispatch.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        There's a specific set of ops meant for the range operator.
        In general, yes, but those aren't used at all in this optimization. The only compilation difference between for (1..4) { } and for (1,4) { } is the former sets OPf_STACKED on the enteriter op. </c>
        t's much better than the longhand for(;;) which would be lots of more ops to dispatch.
        Yes.