2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>strict - Perl pragma to restrict unsafe constructs
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> strict - Perl pragma to restrict unsafe constructs
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
25 <li><a href=
"#history">HISTORY
</a></li>
32 <h1><a name=
"name">NAME
</a></h1>
33 <p>strict - Perl pragma to restrict unsafe constructs
</p>
37 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
41 use strict
"vars
";
42 use strict
"refs
";
43 use strict
"subs
";
</pre>
46 no strict
"vars
";
</pre>
50 <h1><a name=
"description">DESCRIPTION
</a></h1>
51 <p>If no import list is supplied, all possible restrictions are assumed.
52 (This is the safest mode to operate in, but is sometimes too strict for
53 casual programming.) Currently, there are three possible things to be
54 strict about: ``subs'', ``vars'', and ``refs''.
</p>
56 <dt><strong><a name=
"item_strict_refs"><code>strict refs
</code></a></strong>
59 <p>This generates a runtime error if you
60 use symbolic references (see
<a href=
"file://C|\msysgit\mingw\html/pod/perlref.html">the perlref manpage
</a>).
</p>
67 $ref =
"foo
";
68 print $$ref; # runtime error; normally ok
69 $file =
"STDOUT
";
70 print $file
"Hi!
"; # error; note: no comma after $file
</pre>
73 <p>There is one exception to this rule:
</p>
81 <p>is allowed so that
<code>goto
&$AUTOLOAD
</code> would not break under stricture.
</p>
84 <dt><strong><a name=
"item_strict_vars"><code>strict vars
</code></a></strong>
87 <p>This generates a compile-time error if you access a variable that wasn't
88 declared via
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_our"><code>our
</code></a> or
<code>use vars
</code>,
89 localized via
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_my"><code>my()
</code></a>, or wasn't fully qualified. Because this is to avoid
90 variable suicide problems and subtle dynamic scoping issues, a merely
91 <code>local()
</code> variable isn't good enough. See
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_my">my in the perlfunc manpage
</a> and
92 <a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#local">local in the perlfunc manpage
</a>.
</p>
97 $X::foo =
1; # ok, fully qualified
98 my $foo =
10; # ok, my() var
99 local $foo =
9; # blows up
</pre>
104 our $bar; # Declares $bar in current package
105 $bar = 'HgS'; # ok, global declared via pragma
</pre>
108 <p>The
<code>local()
</code> generated a compile-time error because you just touched a global
109 name without fully qualifying it.
</p>
112 <p>Because of their special use by sort(), the variables $a and $b are
113 exempted from this check.
</p>
116 <dt><strong><a name=
"item_strict_subs"><code>strict subs
</code></a></strong>
119 <p>This disables the poetry optimization, generating a compile-time error if
120 you try to use a bareword identifier that's not a subroutine, unless it
121 is a simple identifier (no colons) and that it appears in curly braces or
122 on the left hand side of the
<code>=
></code> symbol.
</p>
127 $SIG{PIPE} = Plumber; # blows up
128 $SIG{PIPE} =
"Plumber
"; # just fine: quoted string is always ok
129 $SIG{PIPE} = \
&Plumber; # preferred form
</pre>
133 <p>See
<a href=
"file://C|\msysgit\mingw\html/pod/perlmodlib.html#pragmatic_modules">Pragmatic Modules in the perlmodlib manpage
</a>.
</p>
137 <h1><a name=
"history">HISTORY
</a></h1>
138 <p><code>strict 'subs'
</code>, with Perl
5.6.1, erroneously permitted to use an unquoted
139 compound identifier (e.g.
<code>Foo::Bar
</code>) as a hash key (before
<code>=
></code> or
140 inside curlies), but without forcing it always to a literal string.
</p>
141 <p>Starting with Perl
5.8.1 strict is strict about its restrictions:
142 if unknown restrictions are used, the strict pragma will abort with
</p>
144 Unknown 'strict' tag(s) '...'
</pre>
145 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
146 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
147 <big><strong><span class=
"block"> strict - Perl pragma to restrict unsafe constructs
</span></strong></big>