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

> All scopes here are determined at compile time.

Only lexical aka static scopes.

Eg local has a dynamic scope .

Check the definitions.

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

  • Comment on Re^2: Disabling runtime warnings in dynamic scope?

Replies are listed 'Best First'.
Re^3: Disabling runtime warnings in dynamic scope?
by shmem (Chancellor) on Apr 26, 2018 at 09:51 UTC

    Only lexical aka static scopes.

    Eg local has a dynamic scope.

    <edit>
    Because of LanX answer below:

    Well, local has no scope at all - it just masks a (package) global at runtime until the localizing goes out of (lexical) scope, but that's just nitpicking at wording perhaps. See also my/local, space/time (was: Re: The difference between my and local).

    local has a static scope. Localized variables have a dynamic scope.
    </edit>

    But here you answered the question for yourself. The warning bits are compiled into each lexical scope at compile time, and a local $^W = $my_bits doesn't change them at runtime for scopes further down.

    So there are two possibilities:

    1. localize $SIG{__WARN__} to propagate a runtime behavior
    2. compile and eval code to be called with a current $^W at runtime
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      ... 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() ;
        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!

        Dynamic scoping might be well defined, but Perl Glossary doesn't do a good job. Looking at Lexical Scoping, most people won't be any wiser.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of