Pragmas
Many programming languages allow you to give hints to
the compiler. In Perl, these hints are conveyed to the compiler with
the use declaration. Some pragmas are:
use warnings; use strict; use integer; use bytes; use constant pi => ( 4 * atan2(1,1) );
Perl pragmas are all described in Glossary, but right now we'll just talk specifically about a couple that are most useful with the material covered in this chapter.
Although a few pragmas are global declarations that
affect global variables or the current package, most are lexically
scoped declarations whose effects are constrained to last only until
the end of the enclosing block, file, or eval
(whichever comes first). A lexically scoped pragma can be
countermanded in an inner scope with a no
declaration, which works just like use but in
reverse.
Controlling Warnings
To show how this works, we'll manipulate the
warnings pragma to tell Perl whether to issue
warnings for questionable practices:
use warnings; # Enable warnings from here till end of file.
…
{
no warnings; # Disable warnings through end of block.
…
}
# Warnings are automatically enabled again here.Once warnings are enabled, Perl complains about variables used only once, variable declarations that mask other declarations in the same scope, improper conversions of strings into numbers, using undefined values as legitimate strings or numbers, trying to write to files you only opened read-only (or didn't open at all), and many other conditions documented in Chapter 33 ...