Yes, 'use encoding'/'no encoding' are per script, but not per block lexical. However your interpretation/understanding is wrong. The following examples could help you to understand:
  1. In a package, if you say:
    ... (block 1)
    use encoding "greek";
    ... (block 2)
    no encoding;
    ... (block 3)
    
    The actual effect is encoding in block 2, but no encoding in block 1, and 3. It is not as you expected that, becasue that no encoding comes the last, the whole module is no encoding.
  2. In a package, if you say:
    ... (block 1)
    use encoding "greek";
    ... (block 2)
    use encoding "greek";
    ... (block 3)
    no encoding;
    ... (block 4)
    
    The actual effect is encoding in block 2 and 3, but no encoding in block 1 and 4. Again, according to your interpretation, the whole module is not encoding becasue that 'no encoding' is the last in the physical sequence. And again your interpretation is wrong.
  3. NOW WHAT DOES THAT SENTENCE IN "encoding" documentation MEAN? Let's get to the point:

    In packageA, you say:
    ...(block 1)
    use encoding "greek";
    ...(block 2)
    
    In a script, you say:
    use packageA;
    ...(block3)
    
    In this example, you should expect, block 1 not encoding, block 2 encoding. Block 3? Now this is what the document means: block 3 is encoding, because that use encoding in packageA is not block lexical, but per script, and your script now 'contains' packageA, that use encoding you put in packageA does affect the rest of the script, not just to the end of packageA.
  4. Another example: In packageA, you say:
    ...(block 1)
    use encoding "greek";
    ...(block 2)
    
    In a script, you say:
    use packageA;
    ...(block3)
    no encoding;
    ...(block 4)
    
    It would be encoding in block 2 and 3, no encoding in 1 and 4. The reason block 3 is encoding is that, the 'use encoding' you put in packageA is per script, so it even affects things outside the package, until meets a 'no encoding' later in the script.
  5. Last example, and this is what you are supposed to do in the best practice.

    In packageA, you say:
    ...(block 1)
    use encoding "greek";
    ...(block 2)
    no encoding; # at the end of packageA
    
    In a script, you say:
    use packageA;
    ...(block 3)
    use encoding "greek";
    ...(block 4)
    
    Block 1, 3 not encoing, 2 and 4 encoding, exactly meets what you visually see on the screen, what you see is what you get. So the best practice is to always say "no encoding" at the end of your module, if you said any "use encoding" earlier in your module. This makes sure that your module's encoding does not affect any other module/script unexpectedly.

In reply to Re: Unicode, regex's, encodings, and all that (Perl 5.6 and 5.8) by pg
in thread Unicode, regex's, encodings, and all that (Perl 5.6 and 5.8) by John M. Dlugosz

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.