=head1 NAME
-perlfaq7 - General Perl Language Issues ($Revision: 1.15 $, $Date: 2003/07/24 02:17:21 $)
+perlfaq7 - General Perl Language Issues ($Revision: 1.18 $, $Date: 2004/11/03 22:54:08 $)
=head1 DESCRIPTION
no warnings; # temporarily turn off warnings
$a = $b + $c; # I know these might be undef
}
+
+Additionally, you can enable and disable categories of warnings.
+You turn off the categories you want to ignore and you can still
+get other categories of warnings. See L<perllexwarn> for the
+complete details, including the category names and hierarchy.
+
+ {
+ no warnings 'uninitialized';
+ $a = $b + $c;
+ }
If you have an older version of Perl, the C<$^W> variable (documented
in L<perlvar>) controls runtime warnings for a block:
Here's a classic function-generating function:
sub add_function_generator {
- return sub { shift + shift };
+ return sub { shift() + shift() };
}
$add_sub = add_function_generator();
sub make_adder {
my $addpiece = shift;
- return sub { shift + $addpiece };
+ return sub { shift() + $addpiece };
}
$f1 = make_adder(20);
=head2 How can I comment out a large block of perl code?
-You can use embedded POD to discard it. The =for directive
-lasts until the next paragraph (two consecutive newlines).
+You can use embedded POD to discard it. Enclose the blocks you want
+to comment out in POD markers, for example C<=for nobody> and C<=cut>
+(which marks ends of POD blocks).
# program is here
=for nobody
- This paragraph is commented out
-
- # program continues
-
-The =begin and =end directives can contain multiple
-paragraphs.
-
- =begin comment text
all of this stuff
here will be ignored
by everyone
- =end comment text
+ =cut
+
+ # program continues
The pod directives cannot go just anywhere. You must put a
pod directive where the parser is expecting a new statement,
not just in the middle of an expression or some other
-arbitrary s grammar production.
+arbitrary grammar production.
See L<perlpod> for more details.