Perl 5.001
[p5sagit/p5-mst-13.2.git] / pod / modpods / strict.pod
CommitLineData
a0d0e21e 1=head1 NAME
2
3strict - 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
18If 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
20casual programming.) Currently, there are three possible things to be
21strict about: "subs", "vars", and "refs".
a0d0e21e 22
23=over 6
24
25=item C<strict refs>
26
27This generates a runtime error if you
28use 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
38This generates a compile-time error if you access a variable that wasn't
39localized via C<my()> or wasn't fully qualified. Because this is to avoid
40variable suicide problems and subtle dynamic scoping issues, a merely
41local() variable isn't good enough. See L<perlfunc/my> and
42L<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
49The local() generated a compile-time error because you just touched a global
50name without fully qualifying it.
51
52=item C<strict subs>
53
54This disables the poetry optimization,
55generating a compile-time error if you
748a9306 56try 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
64See L<perlmod/Pragmatic Modules>.
65