Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: Disabling runtime warnings in dynamic scope?

by Veltro (Hermit)
on Apr 26, 2018 at 12:52 UTC ( [id://1213600]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Disabling runtime warnings in dynamic scope?
in thread Disabling runtime warnings in dynamic scope?

... and a local $^W = $my_bits doesn't change them at runtime for scopes further down ...

What do you mean? This works fine:

use strict; my $lasthash = { lastfunc => sub { last ; }, } ; sub lastfunc { last ; } sub test { # local ($^W) = 1 ; # Activate this line to display the warnings while(1) { lastfunc } ; while(1) { $lasthash->{lastfunc}->(); } ; } test() ;

Replies are listed 'Best First'.
Re^5: Disabling runtime warnings in dynamic scope?
by LanX (Saint) on Apr 26, 2018 at 13:13 UTC
    I think two variables where confused here, $^W is dynamically scoped but can hold only one boolean state, not a variety of warning bits like ${^WARNING_BITS} .

    From perlvar

    ● $WARNING

    ● $^W

    The current value of the warning switch, initially true if -w was used, false otherwise, but directly modifiable.

    See also warnings.

    Mnemonic: related to the -w switch.

    ● ${^WARNING_BITS}

    The current set of warning checks enabled by the use warnings pragma. It has the same scoping as the $^H and %^H variables. The exact values are considered internal to the warnings pragma and may change between versions of Perl.

    This variable was added in Perl v5.6.0.

    I suppose that ${^WARNING_BITS} * can be dynamically changed, but then only with great care (I wouldn't be surprised if implementation changed)

    The bits are supposed to be set by use warnings which is statically scoped, hence here are dragons!

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery

    *) to answer my own suspicion, ${^WARNING_BITS} are only set at compile-time and undef at run-time!

      FWIW, like suspected, ${^WARNING_BITS} is a pure compile time effect, no dynamic scope possible.

      use strict; use warnings; use Data::Dump qw/pp dd/; my ($before,$after); BEGIN { $before = ${^WARNING_BITS} } no warnings 'exiting'; BEGIN { $after = ${^WARNING_BITS} } my $diff = $before ^ $after; warn unpack ('B*',$diff); { use warnings; BEGIN { ${^WARNING_BITS} = $after }; # this only works at compile + time!!! sub test {last }; test(); }

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

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

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

    No recent polls found