in reply to What's the Right Way to declare constants in packages?
An optimization in the Perl compiler recognizes does some special optimizations when a function is declared with a () prototype is not called with either a do or an &. If after all the smoke and magic the function returns a constant value, this value will be substituted directly into the code, instead of incurring the subroutine call overhead each time.
I have done both - there are times when use constant is more useful ( standardized, don't have to think how it works, etc ) and there are times when declaring you own subroutines is useful ( lots of them, defining all your constants in one file, etc ).
For more information, read perldoc perlsub and search on the string 'Constant Functions'
|
|---|