Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl Constants

by robin (Chaplain)
on Dec 29, 2005 at 17:24 UTC ( #519806=note: print w/ replies, xml ) Need Help??


in reply to Perl Constants

There are at least two significant advantages:

  1. The use constant syntax is easier to read and understand, especially to someone who is not a Perl expert.
  2. A constant defined with use constant will be inlined at compile time, which is more efficient than looking up the value at run time (if the constant is used more than once).
The disadvantage is that it's more difficult to include the constant value in a string: you have to say
print "The value is ".CONSTANT.".\n";
instead of
print "The value is $CONSTANT.\n";
which is a little more visually cluttered. On the other hand, the advantage of inlining is even more pronounced in this case, as the concatenations will be optimized away in the first example, but not in the second.

On balance, I think it's usually better to use constant.


Comment on Re: Perl Constants
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-07-31 22:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (254 votes), past polls