use strict; # Install all three strictures. use strict "vars"; # Variables must be predeclared use strict "refs"; # Can't use symbolic references use strict "subs"; # Bareword strings must be quoted use strict; # Install all... no strict "vars"; # ...then renege on one use v5.12; # by default with v5.12.0 or later
This lexically scoped pragma changes some basic rules about what
Perl considers to be legal code. Sometimes these restrictions seem too
strict for casual programming, such as when you’re just trying to whip up
a five-line filter program. The larger your program, the stricter you need
to be about it. If you declare a minimum version of perl with
use, and that minimum version is v5.12 or later,
you get strictures implicitly.
Currently, there are three possible things to be strict about:
refs. If no import list is supplied, all three
restrictions are assumed.
This generates a runtime error if you try to dereference a string instead of a reference, whether intentionally or otherwise.
See Chapter 8 for more about these.
use strict "refs"; $ref = \$foo; # Store "real" (hard) reference print $$ref; # Dereferencing is ok $ref = "foo"; # Store name of global (package) variable print $$ref; # WRONG, runtime error under strict refs
Symbolic references are suspect for various reasons. It’s
surprisingly easy for even well-meaning programmers to invoke them
strict "refs" guards against that. Unlike real references, symbolic references can ...