Pragmas
Pragmas are special modules that come with each release of Perl
and tell Perl’s internal compiler something about your code. You’ve
already used the strict pragma. The
pragmas available for your release of Perl should be listed in the
perlmodlib manpage.
You use pragmas much like you’d use ordinary modules, with a
use directive. Some pragmas are
lexically scoped, like lexical (my)
variables are, and they therefore apply to the smallest enclosing block
or file. Others may apply to the entire program or to the current
package. (If you don’t use any packages, the pragmas apply to your
entire program.) Pragmas should generally appear near the top of your
source code. The documentation for each pragma should tell you how it’s
scoped.
The constant Pragma
If you’ve used other languages, you’ve probably seen the ability to
declare constants in one way or another. Constants are handy for
making a setting just once, near the beginning of a program, but that
can easily be updated if the need arises. Perl can do this with the
package-scoped constant pragma,
which tells the compiler that a given identifier has a constant value,
which may thus be optimized wherever it appears. For example:
use constant DEBUGGING => 0;
use constant ONE_YEAR => 365.2425 * 24 * 60 * 60;
if (DEBUGGING) {
# This code will be optimized away unless DEBUGGING is turned on
...
}The diagnostics Pragma
Perl’s diagnostic messages often seem somewhat cryptic, at least the first time you see them. But you can always look ...