Maybe for discussion rather than revelation, but why use constants as sub-routines?
Constant functions can be used to optimize away parts of your program, are just as fast as regular scalars, and they can't be modified "accidentally". You can create these automatically with
use constant FOO => 'bar';
Regular variables can be created faster (no module import required), used inside strings without special handling, and are often more "user friendly" in this regard.
There was a module called
Tie::Const which created "read-only" variables using, of course,
tie. The end result is slower scalars, just so you can put them in strings directly and have the piece of mind that they aren't being modified. This seems like a sub-optimal solution, and indeed, the module has been decommissioned.
I'd rather see something like this in the future:
my const $FOO = 'bar'; # This is preferable, excuse my C++
my $FOO : const = 'bar'; # This is "more Perly"
const is really useful when applied correctly, but Perl has no such mechanism. This is a huge drawback when it comes to optimization.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.