Shawn Corey misstated the issue, it isn't that -w can't be turned off, the
problem is that it is turned on globally rather than lexically. That is, it
forces warnings onto modules that may have been designed to not use
warnings:

$ cat T.pm
package T;

sub foo {
        my $x = shift;
        # undef or string is perfectly cromulant here
        return $x + 1;
}

1;
$ cat t.pl
#!/usr/bin/perl

use strict;
use warnings;

use T;

print T::foo, "\n";
$ perl t.pl
1
$ perl -w t.pl
Use of uninitialized value $x in addition (+) at T.pm line 6.
1




On Sun, Oct 29, 2017 at 7:29 PM John W. Krahn <jwkr...@shaw.ca> wrote:

> On Sun, 2017-07-02 at 11:16 -0400, Shawn H Corey wrote:
> > On Sun, 2 Jul 2017 14:29:25 +0200
> > Eric de Hont <eric-pml...@hobiho.nl> wrote:
> >
> > > What it boils down to: use warnings as well as -w works, but -w is
> > > considered old fashioned.
> >
> > The problem with -w is that it can't be turned off.
>
> $ perl -le'
> use warnings;
> my $x;
> {       no warnings;
>         print $x;
>         }
> print $x;
> '
>
> Use of uninitialized value $x in print at -e line 7.
>
> $ perl -wle'
> my $x;
> {       local $^W = 0;
>         print $x;
>         }
> print $x;
> '
>
> Use of uninitialized value $x in print at -e line 6.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to