Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Shouldn't LITERAL references be readonly? (updated)by ikegami (Patriarch) |
on Aug 06, 2020 at 04:12 UTC ( [id://11120393]=note: print w/replies, xml ) | Need Help?? |
Both the hash constructor ({}) and the array constructor ([]) create a fresh variable and a fresh reference to it. "TEST", 42 and undef do not create anything; they simply place a previously-constructed scalar on the stack. Changing these scalars would be bad, so they are protected from being changed. For example, take the following code:
Before 5.20, it output the following:
That is something that isn't read-only but should be. If "TEST", 42 or undef weren't read-only, a similar problem would occur.[1] There's no such problem with the newly created references from {} and []. {} and [] are akin to "<$x>" (also not read-only), not "TEST".
In Section
Seekers of Perl Wisdom
|
|