X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperllexwarn.pod;h=20f1875c0cbd18857e603ac62369e2539e034fb9;hb=8269e00da02a2e0f107fbb8b4a78f0c4058f3587;hp=0052d33ff2bc44e2d25461e6eef4cf8f9fb3347e;hpb=ee8c7f5465f003860e2347a2946abacac39bd9b9;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perllexwarn.pod b/pod/perllexwarn.pod index 0052d33..20f1875 100644 --- a/pod/perllexwarn.pod +++ b/pod/perllexwarn.pod @@ -1,4 +1,5 @@ =head1 NAME +X X X perllexwarn - Perl Lexical Warnings @@ -19,29 +20,28 @@ doesn't attempt to control the warnings will work unchanged. All warnings are enabled in a block by either of these: - use warnings ; - use warnings 'all' ; + use warnings; + use warnings 'all'; Similarly all warnings are disabled in a block by either of these: - no warnings ; - no warnings 'all' ; + no warnings; + no warnings 'all'; For example, consider the code below: - use warnings ; - my $a ; - my $b ; + use warnings; + my @a; { - no warnings ; - $b = 2 if $a EQ 3 ; + no warnings; + my $b = @a[0]; } - $b = 1 if $a NE 3 ; + my $c = @a[0]; The code in the enclosing block has warnings enabled, but the inner -block has them disabled. In this case that means that the use of the C -operator won't trip a C<"Use of EQ is deprecated"> warning, but the use of -C will produce a C<"Use of NE is deprecated"> warning. +block has them disabled. In this case that means the assignment to the +scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]"> +warning, but the assignment to the scalar C<$b> will not. =head2 Default Warnings and Optional Warnings @@ -63,7 +63,7 @@ example, in the code below, an C<"isn't numeric"> warning will only be reported for the C<$a> variable. my $a = "2:" + 3; - no warnings ; + no warnings; my $b = "2:" + 3; Note that neither the B<-w> flag or the C<$^W> can be used to @@ -83,9 +83,9 @@ fundamentally flawed. For a start, say you want to disable warnings in a block of code. You might expect this to be enough to do the trick: { - local ($^W) = 0 ; - my $a =+ 2 ; - my $b ; chop $b ; + local ($^W) = 0; + my $a =+ 2; + my $b; chop $b; } When this code is run with the B<-w> flag, a warning will be produced @@ -96,11 +96,11 @@ disable compile-time warnings you need to rewrite the code like this: { BEGIN { $^W = 0 } - my $a =+ 2 ; - my $b ; chop $b ; + my $a =+ 2; + my $b; chop $b; } -The other big problem with C<$^W> is that way you can inadvertently +The other big problem with C<$^W> is the way you can inadvertently change the warning setting in unexpected places in your code. For example, when the code below is run (without the B<-w> flag), the second call to C will trip a C<"Use of uninitialized value"> warning, whereas @@ -108,13 +108,13 @@ the first will not. sub doit { - my $b ; chop $b ; + my $b; chop $b; } - doit() ; + doit(); { - local ($^W) = 1 ; + local ($^W) = 1; doit() } @@ -131,6 +131,7 @@ warnings are (or aren't) produced: =over 5 =item B<-w> +X<-w> This is the existing flag. If the lexical warnings pragma is B used in any of you code, or any of the modules that you use, this flag @@ -138,6 +139,7 @@ will enable warnings everywhere. See L for details of how this flag interacts with lexical warnings. =item B<-W> +X<-W> If the B<-W> flag is used on the command line, it will enable all warnings throughout the program regardless of whether warnings were disabled @@ -146,6 +148,7 @@ included via C, C or C. Think of it as the Perl equivalent of the "lint" command. =item B<-X> +X<-X> Does the exact opposite to the B<-W> flag, i.e. it disables all warnings. @@ -200,6 +203,7 @@ the C pragma to control the warning behavior of $^W-type code (using a C) if it really wants to, but not vice-versa. =head2 Category Hierarchy +X A hierarchy of "categories" have been defined to allow groups of warnings to be enabled/disabled in isolation. @@ -208,10 +212,12 @@ The current hierarchy is: all -+ | - +- chmod + +- assertions | +- closure | + +- deprecated + | +- exiting | +- glob @@ -222,6 +228,8 @@ The current hierarchy is: | | | +- exec | | + | +- layer + | | | +- newline | | | +- pipe @@ -266,8 +274,6 @@ The current hierarchy is: | | | +- bareword | | - | +- deprecated - | | | +- digit | | | +- parenthesis @@ -286,7 +292,7 @@ The current hierarchy is: | +- taint | - +- umask + +- threads | +- uninitialized | @@ -297,51 +303,80 @@ The current hierarchy is: +- utf8 | +- void - | - +- y2k Just like the "strict" pragma any of these categories can be combined - use warnings qw(void redefine) ; - no warnings qw(io syntax untie) ; + use warnings qw(void redefine); + no warnings qw(io syntax untie); Also like the "strict" pragma, if there is more than one instance of the C pragma in a given scope the cumulative effect is additive. - use warnings qw(void) ; # only "void" warnings enabled + use warnings qw(void); # only "void" warnings enabled ... - use warnings qw(io) ; # only "void" & "io" warnings enabled + use warnings qw(io); # only "void" & "io" warnings enabled ... - no warnings qw(void) ; # only "io" warnings enabled + no warnings qw(void); # only "io" warnings enabled To determine which category a specific warning has been assigned to see L. +Note: In Perl 5.6.1, the lexical warnings category "deprecated" was a +sub-category of the "syntax" category. It is now a top-level category +in its own right. + + =head2 Fatal Warnings +X The presence of the word "FATAL" in the category list will escalate any warnings detected from the categories specified in the lexical scope -into fatal errors. In the code below, there are 3 places where a -deprecated warning will be detected, the middle one will produce a -fatal error. +into fatal errors. In the code below, the use of C