I know it's been discussed before, I'm not a SuperSearch guru. *sighs*

Why the change to read-only lists in 5.6.x?

foreach my $value (qw(a b c)) { $value .= '1'; print "$value\n"; }
That works under 5.0.x, but not 5.6.x ... I personally like the change, but can't remember why it happened. (A coworker asked me, bitching about a script that now doesn't work.)

------
We are the carpenters and bricklayers of the Information Age.

Vote paco for President!

Replies are listed 'Best First'.
Re: Why the change to read-only lists in 5.6.x?
by japhy (Canon) on Sep 05, 2001 at 18:45 UTC
    The change has occurred because qw() no longer becomes split ' ', q() at compile-time. The reason for that was because qw() in scalar context was splitting to @_ and returning the number of elements (which is probably less than good). So now, qw() is turned into a physical list at compile-time. That means your code is:
    foreach my $value (('a', 'b', 'c')) { $value .= '1'; print "$value\n"; }
    So you're trying to modify constants. Note, also, that now you can directly subscript a qw(), or use it in a for statement without surrounding parentheses:
    $vowel = qw( a e i o u )[ rand 5 ]; for qw( a e i o u ) { # ... }
    Weird looking, eh?

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: Why the change to read-only lists in 5.6.x?
by trantor (Chaplain) on Sep 05, 2001 at 17:38 UTC

    It seems to be coherent with the fact that a, b and c are constants, not lvalues, so you should not be allowed to modify their value.

    -- TMTOWTDI