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:
Rafael Garcia-Suarez
Date:
November 26, 2009 00:37
Subject:
Re: [PATCH] Perl RT#3105 Mark elements of constant range as read only
Message ID:
b77c1dce0911260037i55d5c707kda58a7c91032482@mail.gmail.com
2009/11/25 David Golden <xdaveg@gmail.com>:
> On Wed, Nov 25, 2009 at 3:33 PM, Abigail <abigail@abigail.be> wrote:
>> I've written code in past like this:
>>
>>    for (1 .. 3) {
>>        $_ .= "foo";
>>        say;
>>    }
>
> Yes, but if that was (1,2,3), it would fail.  E.g., currently:
>
>  $ perl -E 'for (1, 2, 3) { $_.="foo"; say }'
>  Modification of a read-only value attempted at -e line 1.
>
>  $ perl -E 'for (1 .. 3) { $_.="foo"; say }'
>  1foo
>  2foo
>  3foo
>
> So I think making constant *range* act like a constant *list* is
> "fixing a bug" not "breaking a feature".

I'd rather have it the other way around : make the for(1,2,3) variant
work, with some sort of copy-on-write.

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