diff options
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perl.pod | 3 | ||||
-rw-r--r-- | pod/perldata.pod | 6 | ||||
-rw-r--r-- | pod/perldbmfilter.pod | 5 | ||||
-rw-r--r-- | pod/perlfaq3.pod | 3 | ||||
-rw-r--r-- | pod/perlfaq4.pod | 5 | ||||
-rw-r--r-- | pod/perlfaq7.pod | 18 | ||||
-rw-r--r-- | pod/perlfilter.pod | 1 | ||||
-rw-r--r-- | pod/perlipc.pod | 4 | ||||
-rw-r--r-- | pod/perlmod.pod | 1 | ||||
-rw-r--r-- | pod/perlmodlib.pod | 4 | ||||
-rw-r--r-- | pod/perlop.pod | 11 | ||||
-rw-r--r-- | pod/perlre.pod | 3 | ||||
-rw-r--r-- | pod/perlref.pod | 3 | ||||
-rw-r--r-- | pod/perlrun.pod | 3 | ||||
-rw-r--r-- | pod/perlstyle.pod | 6 | ||||
-rw-r--r-- | pod/perlsyn.pod | 3 | ||||
-rw-r--r-- | pod/perltie.pod | 4 | ||||
-rw-r--r-- | pod/perltrap.pod | 3 | ||||
-rw-r--r-- | pod/perlunicode.pod | 3 | ||||
-rw-r--r-- | pod/perlxstut.pod | 1 |
20 files changed, 59 insertions, 31 deletions
diff --git a/pod/perl.pod b/pod/perl.pod index f954e10e5f..f90696e8a8 100644 --- a/pod/perl.pod +++ b/pod/perl.pod @@ -392,7 +392,8 @@ Perl developers, please write to perl-thanks@perl.org . =head1 DIAGNOSTICS -The B<-w> switch produces some lovely diagnostics. +The C<use warnings> pragma (and the B<-w> switch) produces some +lovely diagnostics. See L<perldiag> for explanations of all Perl's diagnostics. The C<use diagnostics> pragma automatically turns Perl's normally terse warnings diff --git a/pod/perldata.pod b/pod/perldata.pod index e3361e4dad..96941bd885 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -129,7 +129,8 @@ assignment to an array or hash evaluates the righthand side in list context. Assignment to a list (or slice, which is just a list anyway) also evaluates the righthand side in list context. -When you use Perl's B<-w> command-line option, you may see warnings +When you use the C<use warnings> pragma or Perl's B<-w> command-line +option, you may see warnings about useless uses of constants or functions in "void context". Void context just means the value has been discarded, such as a statement containing only C<"fred";> or C<getpwuid(0);>. It still @@ -366,7 +367,8 @@ A word that has no other interpretation in the grammar will be treated as if it were a quoted string. These are known as "barewords". As with filehandles and labels, a bareword that consists entirely of lowercase letters risks conflict with future reserved -words, and if you use the B<-w> switch, Perl will warn you about any +words, and if you use the C<use warnings> pragma or the B<-w> switch, +Perl will warn you about any such words. Some people may wish to outlaw barewords entirely. If you say diff --git a/pod/perldbmfilter.pod b/pod/perldbmfilter.pod index faed2d25d2..3350596aab 100644 --- a/pod/perldbmfilter.pod +++ b/pod/perldbmfilter.pod @@ -86,6 +86,7 @@ sure you have already guessed, this is a problem that DBM Filters can fix very easily. use strict ; + use warnings ; use SDBM_File ; use Fcntl ; @@ -99,7 +100,8 @@ fix very easily. # Install DBM Filters $db->filter_fetch_key ( sub { s/\0$// } ) ; $db->filter_store_key ( sub { $_ .= "\0" } ) ; - $db->filter_fetch_value( sub { s/\0$// } ) ; + $db->filter_fetch_value( + sub { no warnings 'uninitialized' ;s/\0$// } ) ; $db->filter_store_value( sub { $_ .= "\0" } ) ; $hash{"abc"} = "def" ; @@ -132,6 +134,7 @@ when reading. Here is a DBM Filter that does it: use strict ; + use warnings ; use DB_File ; my %hash ; my $filename = "/tmp/filt" ; diff --git a/pod/perlfaq3.pod b/pod/perlfaq3.pod index 372e1ffda5..b05b7361c0 100644 --- a/pod/perlfaq3.pod +++ b/pod/perlfaq3.pod @@ -48,7 +48,8 @@ uninteresting, but may still be what you want. =head2 How do I debug my Perl programs? -Have you used C<-w>? It enables warnings for dubious practices. +Have you tried C<use warnings> or used C<-w>? They enable warnings +for dubious practices. Have you tried C<use strict>? It prevents you from using symbolic references, makes you predeclare any subroutines that you call as bare diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index ad4824577d..b358a4eaef 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -940,7 +940,8 @@ with @bad[0] = `same program that outputs several lines`; -The B<-w> flag will warn you about these matters. +The C<use warnings> pragma and the B<-w> flag will warn you about these +matters. =head2 How can I remove duplicate elements from a list or array? @@ -1070,7 +1071,7 @@ strings. Modify if you have other needs. sub compare_arrays { my ($first, $second) = @_; - local $^W = 0; # silence spurious -w undef complaints + no warnings; # silence spurious -w undef complaints return 0 unless @$first == @$second; for (my $i = 0; $i < @$first; $i++) { return 0 if $first->[$i] ne $second->[$i]; diff --git a/pod/perlfaq7.pod b/pod/perlfaq7.pod index 0afbc0dd34..d51bf93b10 100644 --- a/pod/perlfaq7.pod +++ b/pod/perlfaq7.pod @@ -84,8 +84,17 @@ Another way is to use undef as an element on the left-hand-side: =head2 How do I temporarily block warnings? -The C<$^W> variable (documented in L<perlvar>) controls -runtime warnings for a block: +If you are running Perl 5.6.0 or better, the C<use warnings> pragma +allows fine control of what warning are produced. +See L<perllexwarn> for more details. + + { + no warnings; # temporarily turn off warnings + $a = $b + $c; # I know these might be undef + } + +If you have an older version of Perl, the C<$^W> variable (documented +in L<perlvar>) controls runtime warnings for a block: { local $^W = 0; # temporarily turn off warnings @@ -95,10 +104,6 @@ runtime warnings for a block: Note that like all the punctuation variables, you cannot currently use my() on C<$^W>, only local(). -A new C<use warnings> pragma is in the works to provide finer control -over all this. The curious should check the perl5-porters mailing list -archives for details. - =head2 What's an extension? A way of calling compiled C code from Perl. Reading L<perlxstut> @@ -168,6 +173,7 @@ own module. Make sure to change the names appropriately. package Some::Module; # assumes Some/Module.pm use strict; + use warnings; BEGIN { use Exporter (); diff --git a/pod/perlfilter.pod b/pod/perlfilter.pod index bf287c0873..c3c83153ad 100644 --- a/pod/perlfilter.pod +++ b/pod/perlfilter.pod @@ -410,6 +410,7 @@ Here is the complete Debug filter: package Debug; use strict; + use warnings; use Filter::Util::Call ; use constant TRUE => 1 ; diff --git a/pod/perlipc.pod b/pod/perlipc.pod index 3ddea3e41b..a9c7e48106 100644 --- a/pod/perlipc.pod +++ b/pod/perlipc.pod @@ -453,8 +453,8 @@ doesn't actually work: open(PROG_FOR_READING_AND_WRITING, "| some program |") -and if you forget to use the B<-w> flag, then you'll miss out -entirely on the diagnostic message: +and if you forget to use the C<use warnings> pragma or the B<-w> flag, +then you'll miss out entirely on the diagnostic message: Can't do bidirectional pipe at -e line 1. diff --git a/pod/perlmod.pod b/pod/perlmod.pod index 994c3eb5dc..63324a41f4 100644 --- a/pod/perlmod.pod +++ b/pod/perlmod.pod @@ -283,6 +283,7 @@ create a file called F<Some/Module.pm> and start with this template: package Some::Module; # assumes Some/Module.pm use strict; + use warnings; BEGIN { use Exporter (); diff --git a/pod/perlmodlib.pod b/pod/perlmodlib.pod index 38044c9157..c1f4aca6be 100644 --- a/pod/perlmodlib.pod +++ b/pod/perlmodlib.pod @@ -1120,7 +1120,9 @@ scheme as the original author. =item Try to design the new module to be easy to extend and reuse. -Always use B<-w>. +Try to C<use warnings;> (or C<use warnings qw(...);>). +Remember that you can add C<no warnings qw(...);> to individual blocks +of code that need less warnings. Use blessed references. Use the two argument form of bless to bless into the class name given as the first parameter of the constructor, diff --git a/pod/perlop.pod b/pod/perlop.pod index a81f7fe8b2..1254948871 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -1097,8 +1097,8 @@ Some frequently seen examples: A common mistake is to try to separate the words with comma or to put comments into a multi-line C<qw>-string. For this reason, the -B<-w> switch (that is, the C<$^W> variable) produces warnings if -the STRING contains the "," or the "#" character. +C<use warnings> pragma and the B<-w> switch (that is, the C<$^W> variable) +produces warnings if the STRING contains the "," or the "#" character. =item s/PATTERN/REPLACEMENT/egimosx @@ -1458,8 +1458,8 @@ the result is not predictable. It is at this step that C<\1> is begrudgingly converted to C<$1> in the replacement text of C<s///> to correct the incorrigible I<sed> hackers who haven't picked up the saner idiom yet. A warning -is emitted if the B<-w> command-line flag (that is, the C<$^W> variable) -was set. +is emitted if the C<use warnings> pragma or the B<-w> command-line flag +(that is, the C<$^W> variable) was set. The lack of processing of C<\\> creates specific restrictions on the post-processed text. If the delimiter is C</>, one cannot get @@ -1597,7 +1597,8 @@ to terminate the loop, they should be tested for explicitly: while (<STDIN>) { last unless $_; ... } In other boolean contexts, C<< <I<filehandle>> >> without an -explicit C<defined> test or comparison elicit a warning if the B<-w> +explicit C<defined> test or comparison elicit a warning if the +C<use warnings> pragma or the B<-w> command-line switch (the C<$^W> variable) is in effect. The filehandles STDIN, STDOUT, and STDERR are predefined. (The diff --git a/pod/perlre.pod b/pod/perlre.pod index 09bee37161..e1f30a324a 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -662,7 +662,8 @@ which uses C<< (?>...) >> matches exactly when the one above does (verifying this yourself would be a productive exercise), but finishes in a fourth the time when used on a similar string with 1000000 C<a>s. Be aware, however, that this pattern currently triggers a warning message under -B<-w> saying it C<"matches the null string many times">): +the C<use warnings> pragma or B<-w> switch saying it +C<"matches the null string many times">): On simple groups, such as the pattern C<< (?> [^()]+ ) >>, a comparable effect may be achieved by negative look-ahead, as in C<[^()]+ (?! [^()] )>. diff --git a/pod/perlref.pod b/pod/perlref.pod index 274f43d029..2727e95ae9 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -528,7 +528,8 @@ makes it more than a bareword: $array{ +shift } $array{ shift @_ } -The B<-w> switch will warn you if it interprets a reserved word as a string. +The C<use warnings> pragma or the B<-w> switch will warn you if it +interprets a reserved word as a string. But it will no longer warn you about using lowercase words, because the string is effectively quoted. diff --git a/pod/perlrun.pod b/pod/perlrun.pod index 5cc1969c60..f1e2c9a62e 100644 --- a/pod/perlrun.pod +++ b/pod/perlrun.pod @@ -701,8 +701,7 @@ can disable or promote into fatal errors specific warnings using C<__WARN__> hooks, as described in L<perlvar> and L<perlfunc/warn>. See also L<perldiag> and L<perltrap>. A new, fine-grained warning facility is also available if you want to manipulate entire classes -of warnings; see L<warnings> (or better yet, its source code) about -that. +of warnings; see L<warnings> or L<perllexwarn>. =item B<-W> diff --git a/pod/perlstyle.pod b/pod/perlstyle.pod index 04aab9854a..bfe5b76713 100644 --- a/pod/perlstyle.pod +++ b/pod/perlstyle.pod @@ -10,7 +10,8 @@ make your programs easier to read, understand, and maintain. The most important thing is to run your programs under the B<-w> flag at all times. You may turn it off explicitly for particular -portions of code via the C<$^W> variable if you must. You should +portions of code via the C<use warnings> pragma or the C<$^W> variable +if you must. You should also always run under C<use strict> or know the reason why not. The C<use sigtrap> and even C<use diagnostics> pragmas may also prove useful. @@ -260,7 +261,8 @@ Line up your transliterations when it makes sense: Think about reusability. Why waste brainpower on a one-shot when you might want to do something like it again? Consider generalizing your code. Consider writing a module or object class. Consider making your -code run cleanly with C<use strict> and B<-w> in effect. Consider giving away +code run cleanly with C<use strict> and C<use warnings> (or B<-w>) in effect +Consider giving away your code. Consider changing your whole world view. Consider... oh, never mind. diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index 7b9590e4de..484af52121 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -171,7 +171,8 @@ statements C<next>, C<last>, and C<redo>. If the LABEL is omitted, the loop control statement refers to the innermost enclosing loop. This may include dynamically looking back your call-stack at run time to find the LABEL. Such -desperate behavior triggers a warning if you use the B<-w> flag. +desperate behavior triggers a warning if you use the C<use warnings> +praga or the B<-w> flag. Unlike a C<foreach> statement, a C<while> statement never implicitly localises any variables. diff --git a/pod/perltie.pod b/pod/perltie.pod index 92040528e9..c835738573 100644 --- a/pod/perltie.pod +++ b/pod/perltie.pod @@ -743,6 +743,7 @@ a scalar. package Remember; use strict; + use warnings; use IO::File; sub TIESCALAR { @@ -845,7 +846,8 @@ have not been flushed to disk. Now that you know what the problem is, what can you do to avoid it? Well, the good old C<-w> flag will spot any instances where you call untie() and there are still valid references to the tied object. If -the second script above is run with the C<-w> flag, Perl prints this +the second script above this near the top C<use warnings 'untie'> +or was run with the C<-w> flag, Perl prints this warning message: untie attempted while 1 inner references still exist diff --git a/pod/perltrap.pod b/pod/perltrap.pod index e528254e0e..261a20fb03 100644 --- a/pod/perltrap.pod +++ b/pod/perltrap.pod @@ -393,7 +393,8 @@ Everything else. If you find an example of a conversion trap that is not listed here, please submit it to Bill Middleton <F<wjm@best.com>> for inclusion. -Also note that at least some of these can be caught with B<-w>. +Also note that at least some of these can be caught with the +C<use warnings> pragma or the B<-w> switch. =head2 Discontinuance, Deprecation, and BugFix traps diff --git a/pod/perlunicode.pod b/pod/perlunicode.pod index c8e31bf66c..5333ac495c 100644 --- a/pod/perlunicode.pod +++ b/pod/perlunicode.pod @@ -118,7 +118,8 @@ a Unicode smiley face is C<\x{263A}>. A character in the Latin-1 range (128..255) should be written C<\x{ab}> rather than C<\xab>, since the former will turn into a two-byte UTF-8 code, while the latter will continue to be interpreted as generating a 8-bit byte rather than a -character. In fact, if C<-w> is turned on, it will produce a warning +character. In fact, if the C<use warnings> pragma of the C<-w> switch +is turned on, it will produce a warning that you might be generating invalid UTF-8. =item * diff --git a/pod/perlxstut.pod b/pod/perlxstut.pod index 88c04ad300..202aa570c4 100644 --- a/pod/perlxstut.pod +++ b/pod/perlxstut.pod @@ -114,6 +114,7 @@ The file Mytest.pm should start with something like this: package Mytest; use strict; + use warnings; require Exporter; require DynaLoader; |