Commit | Line | Data |
a0d0e21e |
1 | =head1 NAME |
2 | |
3 | strict - Perl pragma to restrict unsafe constructs |
4 | |
5 | =head1 SYNOPSIS |
6 | |
7 | use strict; |
8 | |
9 | use strict "vars"; |
10 | use strict "refs"; |
11 | use strict "subs"; |
12 | |
13 | use strict; |
14 | no strict "vars"; |
15 | |
16 | =head1 DESCRIPTION |
17 | |
18 | If no import list is supplied, all possible restrictions are assumed. |
748a9306 |
19 | (This is the safest mode to operate in, but is sometimes too strict for |
20 | casual programming.) Currently, there are three possible things to be |
21 | strict about: "subs", "vars", and "refs". |
a0d0e21e |
22 | |
23 | =over 6 |
24 | |
25 | =item C<strict refs> |
26 | |
27 | This generates a runtime error if you |
28 | use symbolic references (see L<perlref>). |
29 | |
30 | use strict 'refs'; |
31 | $ref = \$foo; |
32 | print $$ref; # ok |
33 | $ref = "foo"; |
34 | print $$ref; # runtime error; normally ok |
35 | |
36 | =item C<strict vars> |
37 | |
38 | This generates a compile-time error if you access a variable that wasn't |
39 | localized via C<my()> or wasn't fully qualified. Because this is to avoid |
40 | variable suicide problems and subtle dynamic scoping issues, a merely |
41 | local() variable isn't good enough. See L<perlfunc/my> and |
42 | L<perlfunc/local>. |
43 | |
44 | use strict 'vars'; |
45 | $X::foo = 1; # ok, fully qualified |
46 | my $foo = 10; # ok, my() var |
47 | local $foo = 9; # blows up |
48 | |
49 | The local() generated a compile-time error because you just touched a global |
50 | name without fully qualifying it. |
51 | |
52 | =item C<strict subs> |
53 | |
54 | This disables the poetry optimization, |
55 | generating a compile-time error if you |
748a9306 |
56 | try to use a bareword identifier that's not a subroutine. |
a0d0e21e |
57 | |
58 | use strict 'subs'; |
59 | $SIG{PIPE} = Plumber; # blows up |
60 | $SIG{"PIPE"} = "Plumber"; # just fine |
61 | |
62 | =back |
63 | |
64 | See L<perlmod/Pragmatic Modules>. |
65 | |