Because use strict; and no strict 'refs'; are compile-time directives, you can't easily check for them during run-time. One way to find out if a certain scope has strict bits set, is to save $^H to a variable in a BEGIN block:
#!/usr/bin/perl STRICT: { use strict; my $strict; BEGIN { $strict = $^H } strict_bits($strict); } NO_STRICT: { no strict; my $strict; BEGIN { $strict = $^H } strict_bits($strict); } sub strict_bits { my $h = shift; # from strict.pm my %bitmask = ( refs => 0x00000002, subs => 0x00000200, vars => 0x00000400 ); printf "\$^H = $h = %b\n", $h; print "strict '$_' is ", (($h & $bitmask{$_}) ? 'on' : 'off' ), "\n" for sort keys %bitmask; } __END__ $^H = 1794 = 11100000010 strict 'refs' is on strict 'subs' is on strict 'vars' is on $^H = 256 = 100000000 strict 'refs' is off strict 'subs' is off strict 'vars' is off
The same idea works for warnings and ${^WARN_BITS}.

My naive understanding is that $^H is attached to a scope (like the "STRICT" block above) during compile-time, in order to make the strict settings work. Apparently you can't access that setting directly during run-time.

Someone with greater B::Deparse-fu will no doubt be able to explain this in more depth.


In reply to Re: Find out, if "use warnings(all)" and "use strict(all)" are used by rhesa
in thread Find out, if "use warnings(all)" and "use strict(all)" are used by Tobiwan

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.