Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / strict.html
blob9b1fda6ae2668b91a4850a13c446587cb6a9a7a4
1 <?xml version="1.0" ?>
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">
4 <head>
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:" />
8 </head>
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">&nbsp;strict - Perl pragma to restrict unsafe constructs</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
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>
26 </ul>
27 <!-- INDEX END -->
29 <hr />
30 <p>
31 </p>
32 <h1><a name="name">NAME</a></h1>
33 <p>strict - Perl pragma to restrict unsafe constructs</p>
34 <p>
35 </p>
36 <hr />
37 <h1><a name="synopsis">SYNOPSIS</a></h1>
38 <pre>
39 use strict;</pre>
40 <pre>
41 use strict &quot;vars&quot;;
42 use strict &quot;refs&quot;;
43 use strict &quot;subs&quot;;</pre>
44 <pre>
45 use strict;
46 no strict &quot;vars&quot;;</pre>
47 <p>
48 </p>
49 <hr />
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>
55 <dl>
56 <dt><strong><a name="item_strict_refs"><code>strict refs</code></a></strong>
58 <dd>
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>
61 </dd>
62 <dd>
63 <pre>
64 use strict 'refs';
65 $ref = \$foo;
66 print $$ref; # ok
67 $ref = &quot;foo&quot;;
68 print $$ref; # runtime error; normally ok
69 $file = &quot;STDOUT&quot;;
70 print $file &quot;Hi!&quot;; # error; note: no comma after $file</pre>
71 </dd>
72 <dd>
73 <p>There is one exception to this rule:</p>
74 </dd>
75 <dd>
76 <pre>
77 $bar = \&amp;{'foo'};
78 &amp;$bar;</pre>
79 </dd>
80 <dd>
81 <p>is allowed so that <code>goto &amp;$AUTOLOAD</code> would not break under stricture.</p>
82 </dd>
83 </li>
84 <dt><strong><a name="item_strict_vars"><code>strict vars</code></a></strong>
86 <dd>
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>
93 </dd>
94 <dd>
95 <pre>
96 use strict 'vars';
97 $X::foo = 1; # ok, fully qualified
98 my $foo = 10; # ok, my() var
99 local $foo = 9; # blows up</pre>
100 </dd>
101 <dd>
102 <pre>
103 package Cinna;
104 our $bar; # Declares $bar in current package
105 $bar = 'HgS'; # ok, global declared via pragma</pre>
106 </dd>
107 <dd>
108 <p>The <code>local()</code> generated a compile-time error because you just touched a global
109 name without fully qualifying it.</p>
110 </dd>
111 <dd>
112 <p>Because of their special use by sort(), the variables $a and $b are
113 exempted from this check.</p>
114 </dd>
115 </li>
116 <dt><strong><a name="item_strict_subs"><code>strict subs</code></a></strong>
118 <dd>
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>=&gt;</code> symbol.</p>
123 </dd>
124 <dd>
125 <pre>
126 use strict 'subs';
127 $SIG{PIPE} = Plumber; # blows up
128 $SIG{PIPE} = &quot;Plumber&quot;; # just fine: quoted string is always ok
129 $SIG{PIPE} = \&amp;Plumber; # preferred form</pre>
130 </dd>
131 </li>
132 </dl>
133 <p>See <a href="file://C|\msysgit\mingw\html/pod/perlmodlib.html#pragmatic_modules">Pragmatic Modules in the perlmodlib manpage</a>.</p>
135 </p>
136 <hr />
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>=&gt;</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>
143 <pre>
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">&nbsp;strict - Perl pragma to restrict unsafe constructs</span></strong></big>
148 </td></tr>
149 </table>
151 </body>
153 </html>