Chapter 29. Pragmatic Modules
A pragma is a special kind of module that affects the compilation phase of
your program. Some pragmatic modules (or pragmata, for short [or pragmas, for shorter]) may also affect the
execution phase of your program. Think of these as hints to the compiler.
Because they need to be seen at compile time, they’ll work only when invoked
by a use or a no, because by the time a require or a do
runs, compilation is long since over.
By convention, pragma names are written all in lowercase, because lowercase module names are reserved for the Perl distribution itself. When writing your own modules, use at least one upper‐ or titlecase character in the module name to avoid conflict with pragma names.
Unlike regular modules, most pragmas limit their effects to the rest
of the innermost enclosing block from which they were invoked. In other
words, they’re lexically scoped, just like my variables. Ordinarily, the lexical scope of an
outer block covers any inner block embedded within it, but an inner block
may countermand a lexically scoped pragma from an outer block by using the
no statement:
use strict;
use integer;
{
no strict "refs"; # allow symbolic references
no integer; # resume floating–point arithmetic
# ....
}More so than the other modules Perl ships with, the pragmas form an integral and essential part of the Perl compilation environment. It’s hard to use the compiler well if you don’t know how to pass hints to it, so we’ll put some extra effort into describing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access