Both forms are correct. If you crack open constant.pm, you will discover all it does is play some neat games with constant functions.

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'

mikfire


In reply to RE: What's the Right Way to declare constants in packages? by mikfire
in thread What's the Right Way to declare constants in packages? by Guildenstern

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.