I would not have come to the idea that a pragma's subpragma might be scoped in another way than the pragma itself or its other subpragmas.

I agree the documentation could be clarified. A bit of historical perspective helps a little: In Perl things generally default(ed) to being global. For example, just like the open pragma, lexically-scoped warnings were introduced in 5.6.0 (before that it was just -w and $^W) - that may be 17 years ago now, but consider that was six years after the release of Perl 5 and nine years after Perl 4. And a lot of the wordings in the documentation haven't really changed over time (including open: this is from the first implementation in March 2000). So keeping in mind the default is "global", when you look at the documentation, it's fairly explicit about which part of use open is lexically scoped.

If I have a lexically scoped pragma at the top my main script, and if I then use another module, the pragma will not be in effect during initialization (i.e. loading and compiling at compile time) of that other module.

Yes, that's a good point! Update: Thinking about this a bit more, some more can be said about the particular current case. Your statement is correct for pragmas like warnings and the lexically-scoped part of the open pragma. But we're talking about STD(IN|OUT|ERR) here, these handles are global and normally stay opened during the entire run of the program, unless they are explicitly changed. That means you'd have to execute code every time the lexical scope changes, but the only mechanism built in to Perl to support lexical scoping of pragmas, $^H and %^H (perlpragma), doesn't really support that directly (although it can be hacked in). So if you wanted to affect those filehandles with an effect in the lexical scope, I think you'd have to get pretty creative with modules like B::Hooks::EndOfScope. So it's not really too surprising that the open pragma isn't that advanced (although doing it for the current dynamic scope would probably be easier). Plus, what would be the use case of switching the handles's encodings mid-run? The terminal isn't going to change encodings all of a sudden, and most likely neither will files piped to and from Perl via the shell. So taking all that into account, it's not really surprising that the :std option is implemented to just globally change the handles.


In reply to Re^7: Which "use" statements in a module do "bubble up" to the callers? (updated) by haukex
in thread Which "use" statements in a module do "bubble up" to the callers? [SOLVED] by Nocturnus

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.