Debian Codegraph @

upstream/opensuse-tumbleweed/man3/strict.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "strict 3pm"
61 .TH strict 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 strict \- Perl pragma to restrict unsafe constructs
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use strict;
72 \&
73 \& use strict "vars";
74 \& use strict "refs";
75 \& use strict "subs";
76 \&
77 \& use strict;
78 \& no strict "vars";
79 .Ve
80 .SH DESCRIPTION
81 .IX Header "DESCRIPTION"
82 The \f(CW\*(C`strict\*(C'\fR pragma disables certain Perl expressions that could behave
83 unexpectedly or are difficult to debug, turning them into errors. The
84 effect of this pragma is limited to the current file or scope block.
85 .PP
86 If no import list is supplied, all possible restrictions are assumed.
87 (This is the safest mode to operate in, but is sometimes too strict for
88 casual programming.) Currently, there are three possible things to be
89 strict about: "subs", "vars", and "refs".
90 .ie n .IP """strict refs""" 6
91 .el .IP "\f(CWstrict refs\fR" 6
92 .IX Item "strict refs"
93 This generates a runtime error if you
94 use symbolic references (see perlref).
95 .Sp
96 .Vb 7
97 \& use strict \*(Aqrefs\*(Aq;
98 \& $ref = \e$foo;
99 \& print $$ref; # ok
100 \& $ref = "foo";
101 \& print $$ref; # runtime error; normally ok
102 \& $file = "STDOUT";
103 \& print $file "Hi!"; # error; note: no comma after $file
104 .Ve
105 .Sp
106 There is one exception to this rule:
107 .Sp
108 .Vb 2
109 \& $bar = \e&{\*(Aqfoo\*(Aq};
110 \& &$bar;
111 .Ve
112 .Sp
113 is allowed so that \f(CW\*(C`goto &$AUTOLOAD\*(C'\fR would not break under stricture.
114 .ie n .IP """strict vars""" 6
115 .el .IP "\f(CWstrict vars\fR" 6
116 .IX Item "strict vars"
117 This generates a compile\-time error if you access a variable that was
118 neither explicitly declared (using any of \f(CW\*(C`my\*(C'\fR, \f(CW\*(C`our\*(C'\fR, \f(CW\*(C`state\*(C'\fR, or \f(CW\*(C`use
119 vars\*(C'\fR) nor fully qualified. (Because this is to avoid variable suicide
120 problems and subtle dynamic scoping issues, a merely \f(CW\*(C`local\*(C'\fR variable isn\*(Aqt
121 good enough.) See "my" in perlfunc, "our" in perlfunc, "state" in perlfunc,
122 "local" in perlfunc, and vars.
123 .Sp
124 .Vb 4
125 \& use strict \*(Aqvars\*(Aq;
126 \& $X::foo = 1; # ok, fully qualified
127 \& my $foo = 10; # ok, my() var
128 \& local $baz = 9; # blows up, $baz not declared before
129 \&
130 \& package Cinna;
131 \& our $bar; # Declares $bar in current package
132 \& $bar = \*(AqHgS\*(Aq; # ok, global declared via pragma
133 .Ve
134 .Sp
135 The \fBlocal()\fR generated a compile\-time error because you just touched a global
136 name without fully qualifying it.
137 .Sp
138 Because of their special use by \fBsort()\fR, the variables \f(CW$a\fR and \f(CW$b\fR are
139 exempted from this check.
140 .ie n .IP """strict subs""" 6
141 .el .IP "\f(CWstrict subs\fR" 6
142 .IX Item "strict subs"
143 This disables the poetry optimization, generating a compile\-time error if
144 you try to use a bareword identifier that\*(Aqs not a subroutine, unless it
145 is a simple identifier (no colons) and that it appears in curly braces,
146 on the left hand side of the \f(CW\*(C`=>\*(C'\fR symbol, or has the unary minus
147 operator applied to it.
148 .Sp
149 .Vb 4
150 \& use strict \*(Aqsubs\*(Aq;
151 \& $SIG{PIPE} = Plumber; # blows up
152 \& $SIG{PIPE} = "Plumber"; # fine: quoted string is always ok
153 \& $SIG{PIPE} = \e&Plumber; # preferred form
154 .Ve
155 .PP
156 See "Pragmatic Modules" in perlmodlib.
157 .SH HISTORY
158 .IX Header "HISTORY"
159 \&\f(CW\*(C`strict \*(Aqsubs\*(Aq\*(C'\fR, with Perl 5.6.1, erroneously permitted to use an unquoted
160 compound identifier (e.g. \f(CW\*(C`Foo::Bar\*(C'\fR) as a hash key (before \f(CW\*(C`=>\*(C'\fR or
161 inside curlies), but without forcing it always to a literal string.
162 .PP
163 Starting with Perl 5.8.1 strict is strict about its restrictions:
164 if unknown restrictions are used, the strict pragma will abort with
165 .PP
166 .Vb 1
167 \& Unknown \*(Aqstrict\*(Aq tag(s) \*(Aq...\*(Aq
168 .Ve
169 .PP
170 As of version 1.04 (Perl 5.10), strict verifies that it is used as
171 "strict" to avoid the dreaded Strict trap on case insensitive file
172 systems.
173 .PP
174 Beginning with Perl 5.12, use of "use VERSION" (where VERSION >= 5.11.0) now
175 lexically enables strictures just like "use strict" (in addition to the normal
176 "use VERSION" effects and features.) In other words, "use v5.011" or higher
177 now implies "use strict" automatically, as noted in
178 "Implicit strictures" in perl5120delta and \f(CW\*(C`use VERSION\*(C'\fR.