Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Please read this first.

    How can I force the internal perl representation to be two-byte utf-8, ... ?

Encode the string of characters.
use Devel::Peek; my $str = "\326"; Dump $str; # not UTF-8 (1 char is 1 byte) my $utf8 = $str; utf8::upgrade($utf8); Dump $utf8; # upgraded to UTF-8 (1 char is 2 bytes) my $utf8_as_bytes = $str; utf8::encode($utf8_as_bytes); Dump $utf8_as_bytes; # not UTF-8 (2 chars with 1 byte each) __END__ SV = PV(0x8519228) at 0x8061e38 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x852b250 "\326"\0 CUR = 1 LEN = 4 SV = PV(0x84556a0) at 0x8528b40 REFCNT = 1 FLAGS = (PADMY,POK,pPOK,UTF8) PV = 0x852b290 "\303\226"\0 [UTF8 "\x{d6}"] CUR = 2 LEN = 3 SV = PV(0x84556a8) at 0x8528730 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x852b2a0 "\303\226"\0 CUR = 2 LEN = 3

In reply to Re: Why does perl's internal utf8 seem to allow single-byte latin1? by repellent
in thread Why does perl's internal utf8 seem to allow single-byte latin1? by brycen

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 examining the Monastery: (7)
As of 2024-04-23 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found