develooper Front page | perl.perl5.porters | Postings from November 2009

Re: [PATCH] Perl RT#3105 Mark elements of constant range as read only

Thread Previous | Thread Next
From:
Eric Brine
Date:
November 26, 2009 09:32
Subject:
Re: [PATCH] Perl RT#3105 Mark elements of constant range as read only
Message ID:
f86994700911260932v490e9512ra8a5d08ee7a56e55@mail.gmail.com
On Thu, Nov 26, 2009 at 5:52 AM, Abigail <abigail@abigail.be> wrote:

> I probably missed it, but which bug is being fixed by forbidding to
> modify the iterator in C<< for $iterator (RANGE) >>?
>

C<< for $x (EXPR..EXPR) >> is special (optimised). It *doesn't* use the
range operator. It shouldn't be affected by the patch. (I'll test when I
can.) If we actually use the range operator, you'll see the problem if you
repeat the statment containing the range. For example,

    for (1..2) {
        for (1 .. 3,@x) {
            $_ .= "foo";
            say;
        }
    }

and

    for (1..2) {
        map {
            $_ .= "foo";
            say
        } 1..3;
    }

both output

    1foo
    2foo
    3foo
    1foofoo
    2foofoo
    3foofoo


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About