1strict(3pm)            Perl Programmers Reference Guide            strict(3pm)
2
3
4

NAME

6       strict - Perl pragma to restrict unsafe constructs
7

SYNOPSIS

9           use strict;
10
11           use strict "vars";
12           use strict "refs";
13           use strict "subs";
14
15           use strict;
16           no strict "vars";
17

DESCRIPTION

19       If no import list is supplied, all possible restrictions are assumed.
20       (This is the safest mode to operate in, but is sometimes too strict for
21       casual programming.)  Currently, there are three possible things to be
22       strict about:  "subs", "vars", and "refs".
23
24       "strict refs"
25             This generates a runtime error if you use symbolic references
26             (see perlref).
27
28                 use strict 'refs';
29                 $ref = \$foo;
30                 print $$ref;        # ok
31                 $ref = "foo";
32                 print $$ref;        # runtime error; normally ok
33                 $file = "STDOUT";
34                 print $file "Hi!";  # error; note: no comma after $file
35
36             There is one exception to this rule:
37
38                 $bar = \&{'foo'};
39                 &$bar;
40
41             is allowed so that "goto &$AUTOLOAD" would not break under
42             stricture.
43
44       "strict vars"
45             This generates a compile-time error if you access a variable that
46             was neither explicitly declared (using any of "my", "our",
47             "state", or "use vars") nor fully qualified.  (Because this is to
48             avoid variable suicide problems and subtle dynamic scoping
49             issues, a merely "local" variable isn't good enough.)  See "my"
50             in perlfunc, "our" in perlfunc, "state" in perlfunc, "local" in
51             perlfunc, and vars.
52
53                 use strict 'vars';
54                 $X::foo = 1;         # ok, fully qualified
55                 my $foo = 10;        # ok, my() var
56                 local $baz = 9;      # blows up, $baz not declared before
57
58                 package Cinna;
59                 our $bar;                   # Declares $bar in current package
60                 $bar = 'HgS';               # ok, global declared via pragma
61
62             The local() generated a compile-time error because you just
63             touched a global name without fully qualifying it.
64
65             Because of their special use by sort(), the variables $a and $b
66             are exempted from this check.
67
68       "strict subs"
69             This disables the poetry optimization, generating a compile-time
70             error if you try to use a bareword identifier that's not a
71             subroutine, unless it is a simple identifier (no colons) and that
72             it appears in curly braces or on the left hand side of the "=>"
73             symbol.
74
75                 use strict 'subs';
76                 $SIG{PIPE} = Plumber;       # blows up
77                 $SIG{PIPE} = "Plumber";     # just fine: quoted string is always ok
78                 $SIG{PIPE} = \&Plumber;     # preferred form
79
80       See "Pragmatic Modules" in perlmodlib.
81

HISTORY

83       "strict 'subs'", with Perl 5.6.1, erroneously permitted to use an
84       unquoted compound identifier (e.g. "Foo::Bar") as a hash key (before
85       "=>" or inside curlies), but without forcing it always to a literal
86       string.
87
88       Starting with Perl 5.8.1 strict is strict about its restrictions: if
89       unknown restrictions are used, the strict pragma will abort with
90
91           Unknown 'strict' tag(s) '...'
92
93       As of version 1.04 (Perl 5.10), strict verifies that it is used as
94       "strict" to avoid the dreaded Strict trap on case insensitive file
95       systems.
96
97
98
99perl v5.16.3                      2013-03-04                       strict(3pm)
Impressum