Debian Codegraph @

upstream/debian-unstable/man3/strict.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (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 .\"
57 .IX Title "strict 3perl"
58 .TH strict 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 strict \- Perl pragma to restrict unsafe constructs
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& use strict;
69 \&
70 \& use strict "vars";
71 \& use strict "refs";
72 \& use strict "subs";
73 \&
74 \& use strict;
75 \& no strict "vars";
76 .Ve
77 .SH DESCRIPTION
78 .IX Header "DESCRIPTION"
79 The \f(CW\*(C`strict\*(C'\fR pragma disables certain Perl expressions that could behave
80 unexpectedly or are difficult to debug, turning them into errors. The
81 effect of this pragma is limited to the current file or scope block.
82 .PP
83 If no import list is supplied, all possible restrictions are assumed.
84 (This is the safest mode to operate in, but is sometimes too strict for
85 casual programming.) Currently, there are three possible things to be
86 strict about: "subs", "vars", and "refs".
87 .ie n .IP """strict refs""" 6
88 .el .IP "\f(CWstrict refs\fR" 6
89 .IX Item "strict refs"
90 This generates a runtime error if you
91 use symbolic references (see perlref).
92 .Sp
93 .Vb 7
94 \& use strict \*(Aqrefs\*(Aq;
95 \& $ref = \e$foo;
96 \& print $$ref; # ok
97 \& $ref = "foo";
98 \& print $$ref; # runtime error; normally ok
99 \& $file = "STDOUT";
100 \& print $file "Hi!"; # error; note: no comma after $file
101 .Ve
102 .Sp
103 There is one exception to this rule:
104 .Sp
105 .Vb 2
106 \& $bar = \e&{\*(Aqfoo\*(Aq};
107 \& &$bar;
108 .Ve
109 .Sp
110 is allowed so that \f(CW\*(C`goto &$AUTOLOAD\*(C'\fR would not break under stricture.
111 .ie n .IP """strict vars""" 6
112 .el .IP "\f(CWstrict vars\fR" 6
113 .IX Item "strict vars"
114 This generates a compile-time error if you access a variable that was
115 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
116 vars\*(C'\fR) nor fully qualified. (Because this is to avoid variable suicide
117 problems and subtle dynamic scoping issues, a merely \f(CW\*(C`local\*(C'\fR variable isn't
118 good enough.) See "my" in perlfunc, "our" in perlfunc, "state" in perlfunc,
119 "local" in perlfunc, and vars.
120 .Sp
121 .Vb 4
122 \& use strict \*(Aqvars\*(Aq;
123 \& $X::foo = 1; # ok, fully qualified
124 \& my $foo = 10; # ok, my() var
125 \& local $baz = 9; # blows up, $baz not declared before
126 \&
127 \& package Cinna;
128 \& our $bar; # Declares $bar in current package
129 \& $bar = \*(AqHgS\*(Aq; # ok, global declared via pragma
130 .Ve
131 .Sp
132 The \fBlocal()\fR generated a compile-time error because you just touched a global
133 name without fully qualifying it.
134 .Sp
135 Because of their special use by \fBsort()\fR, the variables \f(CW$a\fR and \f(CW$b\fR are
136 exempted from this check.
137 .ie n .IP """strict subs""" 6
138 .el .IP "\f(CWstrict subs\fR" 6
139 .IX Item "strict subs"
140 This disables the poetry optimization, generating a compile-time error if
141 you try to use a bareword identifier that's not a subroutine, unless it
142 is a simple identifier (no colons) and that it appears in curly braces,
143 on the left hand side of the \f(CW\*(C`=>\*(C'\fR symbol, or has the unary minus
144 operator applied to it.
145 .Sp
146 .Vb 4
147 \& use strict \*(Aqsubs\*(Aq;
148 \& $SIG{PIPE} = Plumber; # blows up
149 \& $SIG{PIPE} = "Plumber"; # fine: quoted string is always ok
150 \& $SIG{PIPE} = \e&Plumber; # preferred form
151 .Ve
152 .PP
153 See "Pragmatic Modules" in perlmodlib.
154 .SH HISTORY
155 .IX Header "HISTORY"
156 \&\f(CW\*(C`strict \*(Aqsubs\*(Aq\*(C'\fR, with Perl 5.6.1, erroneously permitted to use an unquoted
157 compound identifier (e.g. \f(CW\*(C`Foo::Bar\*(C'\fR) as a hash key (before \f(CW\*(C`=>\*(C'\fR or
158 inside curlies), but without forcing it always to a literal string.
159 .PP
160 Starting with Perl 5.8.1 strict is strict about its restrictions:
161 if unknown restrictions are used, the strict pragma will abort with
162 .PP
163 .Vb 1
164 \& Unknown \*(Aqstrict\*(Aq tag(s) \*(Aq...\*(Aq
165 .Ve
166 .PP
167 As of version 1.04 (Perl 5.10), strict verifies that it is used as
168 "strict" to avoid the dreaded Strict trap on case insensitive file
169 systems.
170 .PP
171 Beginning with Perl 5.12, use of "use VERSION" (where VERSION >= 5.11.0) now
172 lexically enables strictures just like "use strict" (in addition to the normal
173 "use VERSION" effects and features.) In other words, "use v5.011" or higher
174 now implies "use strict" automatically, as noted in
175 "Implicit strictures" in perl5120delta and \f(CW\*(C`use VERSION\*(C'\fR.