Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
If you check in perlvar you will find out that $^H is an internal and highly magical variable. It is just a collection of flags with rather special scoping semantics. What strict does is flip the appropriate bits to what they need to be to cause certain things to (not) be checked when you want them to (not) be.

If it helps, I am willing to treat it as black magic and hope that the phase of the moon is right... :-)

What I suspect (verifying it would take some research) is happening is that $^H is a global variable which the parser is auto-localizing as it goes through blocks. So within strict you write to the global, but within the parser the effect of that modification is scoped to just the current block. Therefore the part of the user code that is affected is apparently lexically scoped.

A couple of other pieces of magic though. First of all when you see an eval, Perl remembers what the correct value of $^H needs to be when it is called. Secondly within a file it needs to essentially do local $^H = $^H; while when it goes out and compiles another file it would have to do local $^H = 0;.

So the magic isn't all that magic, it just looks mysterious because of when it is happening. If you want to test this explanation, each of the following tests another aspect of its behaviour:

perl -e 'print $^H' perl -e 'use strict; print $^H' perl -e 'use strict; no strict; print $^H' perl -e 'use strict; {no strict; print $^H}' perl -e 'use strict; BEGIN {no strict; print $^H}' perl -e 'use strict; {no strict; BEGIN{ print $^H}}'
(People on windows may need to switch quotes.)

In reply to Re (tilly) 1: How does strict work? by tilly
in thread How does strict work? by epoptai

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (2)
    As of 2018-04-22 03:24 GMT
    Find Nodes?
      Voting Booth?