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             wasn't declared via "our" or "use vars", localized via "my()", or
47             wasn't fully qualified.  Because this is to avoid variable
48             suicide problems and subtle dynamic scoping issues, a merely
49             local() variable isn't good enough.  See "my" in perlfunc and
50             "local" in perlfunc.
51
52                 use strict 'vars';
53                 $X::foo = 1;         # ok, fully qualified
54                 my $foo = 10;        # ok, my() var
55                 local $foo = 9;      # blows up
56
57                 package Cinna;
58                 our $bar;                   # Declares $bar in current package
59                 $bar = 'HgS';               # ok, global declared via pragma
60
61             The local() generated a compile-time error because you just
62             touched a global name without fully qualifying it.
63
64             Because of their special use by sort(), the variables $a and $b
65             are exempted from this check.
66
67       "strict subs"
68             This disables the poetry optimization, generating a compile-time
69             error if you try to use a bareword identifier that's not a
70             subroutine, unless it is a simple identifier (no colons) and that
71             it appears in curly braces or on the left hand side of the "=>"
72             symbol.
73
74                 use strict 'subs';
75                 $SIG{PIPE} = Plumber;       # blows up
76                 $SIG{PIPE} = "Plumber";     # just fine: quoted string is always ok
77                 $SIG{PIPE} = \&Plumber;     # preferred form
78
79       See "Pragmatic Modules" in perlmodlib.
80

HISTORY

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