Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by jdtoronto (Prior)
on Jul 06, 2006 at 01:19 UTC ( [id://559459]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://559459]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found