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'

In reply to Re^3: Disabling runtime warnings in dynamic scope? by shmem
in thread Disabling runtime warnings in dynamic scope? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.