in reply to Perl Constants
There are at least two significant advantages:
- The use constant syntax is easier to read and understand, especially to someone who is not a Perl expert.
- 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).
instead ofprint "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.print "The value is $CONSTANT.\n";
On balance, I think it's usually better to use constant.
|
---|
In Section
Seekers of Perl Wisdom