For a nice explanation of use warnings vs. -w and why the former is now prefered over the latter see perllexwarn. The gist of it being that lexically scoped warnings and optional warnings are a good thing™.
| [reply] [Watch: Dir/Any] |
See perldoc for both warnings and perllexwarn. Basically, the warnings pragma gives you lexically scoped warnings and much finer grained control over the warnings. For example, if you don't want "redefined" warnings, but you don't want to suppress all of the other warnings, rather than create a customer $SIG{__WARN__} handler, you can specify no warnings 'redefine'.
| [reply] [Watch: Dir/Any] |
The section from perllexwarn that you might find most interesting comes under the headline, "What's wrong with -w and $^W":
Although very useful, the big problem with using -w on the command line to enable warnings is that it is all or nothing. Take the typical scenario when you are writing a Perl program. Parts of the code you will write yourself, but it's very likely that you will make use of pre-written Perl modules. If you use the -w flag in this case, you end up enabling warnings in pieces of code that you haven't written.
The section then goes on to describe how $^W falls short of providing lexical scoping for -w.
For simple code snippets, -w and use warnings are synonymous. But for more elaborate code, and scripts that use modules, or scripts that need lexical control over warnings, the pragma is preferable over the command-line switch.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Occasionally, a programer who knows what they're doing will create code which causes a non-fatal error to be printed that they know is OK. In such a case, use warnings will allow you to put a no warnings for the area of code in question, but keep the warnings for the rest of the program. OTOH, using -w would require you to shut off warnings for the entire code.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
: () { :|:& };:
Note: All code is untested, unless otherwise stated
| [reply] [Watch: Dir/Any] [d/l] [select] |
There are four responses (as I write this) from monks of stature, but no one has responded to the original question: Is there any point to using both '-w' and 'use warnings' in the same script -- or is that a mistake.
My take is, it's an error. If this is wrong, someone will likely chime in.
------------------------------------------------------------
"Perl is a mess
and that's good because the
problem space is also a mess." - Larry Wall
| [reply] [Watch: Dir/Any] |