|laziness, impatience, and hubris|
Readonly oddityby Anonymous Monk
|on Jan 26, 2016 at 11:00 UTC||Need Help??|
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Consider the following script:
On this system, it generates the following output:
You might have noticed that the script above is subtly broken. I should have written Readonly my $foo => 'bar' . But the mistake is easy to make, as it is very natural to write my $foo = 'bar' and it is plausible to think that "Readonly" works by merely extending this syntax.
The insidious thing is that on this system, with these versions of Perl and Readonly it doesn't complain at all, it just silently leaves the variable undef. Even worse, it appears to work with arrays!
For that matter, the very same script breaks on my other system with Perl 5.14 and Readonly 1.03.
Is this a known problem?
If not, I see two approaches to fix it: