in reply to What is the difference between the constant construct in Perl and the Readonly construct in Perl?

As revdiablo has said Readonly is not a core module, whereas constant is a pragma. There are some shortcomings in the use of the constant pragma and all of those are in fact well pointed out in the documentation for Readonly. However Readonly has a performance penalty and there is at least one 'speed up' module ( Readonly::xs ) on CPAN for it and some useful alternatives. One particularly cunning one is Scalar::Readonly which although it works only on scalars allows you to programatically 'write enable' a variable, update it and then lock it again. Of course the variable can be tested as well.

I will very rarely use constant, I have never used Readonly. We do some tricks using Scalar::Readonly ocasionally.

jdtoronto

  • Comment on Re: What is the difference between the constant construct in Perl and the Readonly construct in Perl?