How about if you show us just enough code to demonstrate the problem -- i.e. assign characters to a scalar, apply substr to the scalar, print the result in some way -- and show us what you actually get as a result. (In the little snippet you showed, there should be a comma between the 0 and the 2.)

For example, this should do what you intended:

my $target = join("", map {chr()} ( 0x5434, 0x9547, 0x5b87 )); my $part = substr( $target, 0, 2 ); print " length of target = ", length($target); print "\n length of substr = ", length( $part ); print "\n $target\n $part\n";
The length function should return the character counts (3 for $target, 2 for $part). If you are using a utf8-aware display window, you should see the two strings in Chinese characters (or redirect to a file, and view that in a utf8-capable display tool, like a browser).

If you get something different, tell us what OS and perl version you have, and be specific about what you actually got.


In reply to Re^3: help needed in unicode displaying by graff
in thread help needed in unicode displaying by uva

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.