go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: 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 reply to Re: Shouldn't LITERAL references be readonly? (updated)
by ikegami
|
|