Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-06-20 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.