in reply to Modification of a read-only value attempted?!?
In the case of for my $x (1) { }, the variable $x is a reference to the value in brackets which is constant.
Consider this: perl -le "my $y = 2; for my $x ($y) { $x = 1; print $y }" When we change $x, we change the underlying $y. So the output is 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Modification of a read-only value attempted?!?
by kikuchiyo (Hermit) on Jan 07, 2024 at 21:07 UTC | |
by haj (Vicar) on Jan 07, 2024 at 21:27 UTC | |
by LanX (Saint) on Jan 07, 2024 at 22:10 UTC | |
|
Re^2: Modification of a read-only value attempted?!?
by jo37 (Curate) on Jan 07, 2024 at 20:57 UTC | |
by ikegami (Patriarch) on Jan 09, 2024 at 19:39 UTC |