Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: strict, warnings and diagnostics pragmas

by John M. Dlugosz (Monsignor)
on Aug 03, 2001 at 20:54 UTC ( [id://102046]=note: print w/replies, xml ) Need Help??


in reply to Re: strict, warnings and diagnostics pragmas
in thread strict, warnings and diagnostics pragmas

use warnings; and perl -w are not the same thing.

Replies are listed 'Best First'.
Re3: strict, warnings and diagnostics pragmas
by Hofmator (Curate) on Aug 07, 2001 at 17:00 UTC

    use warnings; and perl -w are not the same thing.
    I'm aware of that, the different scoping, the possibility to use warnings::register; ... but the way I understand it, use warnings; is not reasonable after setting $^W = 1; # equivalent to perl -w which is done by use diagnostics;. Please correct me if I'm overlooking something here...

    -- Hofmator

      Myth: use warnings is not reasonable after using -w or setting $^W=1.

      In the scope of lexical warnings, the old warning state is ignored. According to perllexwarn,

      If you are used with working with a version of Perl prior to the introduction of lexically scoped warnings, or have code that uses both lexical warnings and $^W, this section will describe how they interact.

      How Lexical Warnings interact with -w/$^W:

      1. If none of the three command line flags (-w, -W or -X) that control warnings is used and neither $^W or the warnings pragma are used, then default warnings will be enabled and optional warnings disabled. This means that legacy code that doesn't attempt to control the warnings will work unchanged.

      2. The -w flag just sets the global $^W variable as in 5.005 -- this means that any legacy code that currently relies on manipulating $^W to control warning behavior will still work as is.

      3. Apart from now being a boolean, the $^W variable operates in exactly the same horrible uncontrolled global way, except that it cannot disable/enable default warnings.

      4. If a piece of code is under the control of the warnings pragma, both the $^W variable and the -w flag will be ignored for the scope of the lexical warning.

      5. The only way to override a lexical warnings setting is with the -W or -X command line flags.

      The combined effect of 3 & 4 is that it will allow code which uses the warnings pragma to control the warning behavior of $^W-type code (using a local $^W=0) if it really wants to, but not vice-versa.

      So, go ahead and use warnings and selectivly enable/disable things as you need. The presence of -w on the command line (or explicit setting of the global flag) will not bother you.

      Code outside of yours will continue to use the -w state; yours (containing use warnings) will hide that and use what you asked for. The hiding of -w by use warnings is itself lexically scoped.

      Also, as specifically pertains to diagnostics.pm, Paul Marquess notes "I *think* I've got diagnostics to work with the lexical warnings patch, but there were design decisions made in diagnostics to work around the limitations of C<$^W>. Now that those limitations are gone, the module should be revisited."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://102046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found