in reply to Re^2: Modification of a read-only value attempted?!?
in thread Modification of a read-only value attempted?!?

The difference is that in for my $x (1) {...} the 1 is a literal constant. (0..1) on the other hand is an expression evaluating to the list (0,1). The loop is aliasing to the anonymous elements of the list, not to the literal boundaries in (0..1).

Perhaps it is helpful to consider that for my $x (0,1) {...} also dies with Modification of a read-only value attempted at -e line 1.

Replies are listed 'Best First'.
Re^4: Modification of a read-only value attempted?!?
by LanX (Saint) on Jan 07, 2024 at 22:10 UTC
    *x = \1 also used to be a common way to define "constants".

    In the OP's case the aliased $x and 1 should have the same reference.

    But there is no point in making temporarily generated values read only, almost all code would break then.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery