Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between "use warnings;" and "use warnings 'all';"?

Tags:

perl

I have the habit of starting each and every of my scripts with

use strict;
use warnings;

But some of the high-rep fellows here recommend

use warnings 'all';

If I understood them right, the latter is even better than the first. So I read through the docs and found

All warnings are enabled in a block by either of these:

use warnings;
use warnings 'all';

Even the Camel Book says nothing different:

use warnings;   # same as importing "all"

So

  • is there a difference, or
  • is it just more future-proof (in case future versions of Perl issue warnings we aren't aware of right now and use warnings; won't catch), or
  • is it just another habit, like e.g. ps -ef vs. ps aux? Some people use this while others prefer the other.
like image 640
PerlDuck Avatar asked Jul 02 '16 16:07

PerlDuck


People also ask

What are warnings in Perl?

use warnings; When the warning pragma is used, the compiler will check for errors, will issue warnings against the code, and will disallow certain programming constructs and techniques. This pragma sends a warning whenever a possible typographical error and looks for possible problems.

What option do you use when starting Perl to tell it to run in warning mode?

The warnings pragma gives control over which warnings are enabled in which parts of a Perl program. It's a more flexible alternative for both the command line flag -w and the equivalent Perl variable, $^W .


1 Answers

Currently,

use warnings;

is equivalent to

use warnings 'all';

However, there has been talk on perl5porters of changing it to mean

use warnings 'default';

New "less-critical" warnings would be added to the "all" category but not shown by default. Since it seems this change is seriously being considered, it's safer to use warnings 'all'; explicitly.

Previous discussions on p5p:

RFC: Support for new warning categories outside of "all"

I've added support for new warning categories outside of "all" to blead

like image 165
ThisSuitIsBlackNot Avatar answered Oct 20 '22 17:10

ThisSuitIsBlackNot