tr and Unicode don't mix well

In what way?  Seems to work fine for me.  Could you provide an example that fails? (just curious)

use Devel::Peek; my $test = "\x{2345}\x{3456}"; Dump $test; $test =~ tr/\x{2345}\x{3456}/XY/; Dump $test; __END__ SV = PV(0x768bc8) at 0x7907d8 REFCNT = 1 FLAGS = (PADMY,POK,pPOK,UTF8) PV = 0x782630 "\342\215\205\343\221\226"\0 [UTF8 "\x{2345}\x{3456}"] CUR = 6 LEN = 8 SV = PV(0x768bc8) at 0x7907d8 REFCNT = 1 FLAGS = (PADMY,POK,pPOK,UTF8) PV = 0x782630 "XY"\0 [UTF8 "XY"] CUR = 2 LEN = 8

(I'm only using \x{...} here because PM code sections don't support Unicode — it works the same way with a UTF-8 encoded source file when using "use utf8;")


In reply to Re^2: tr{}{} doesn't wanna work.. what am I doing wrong? by Eliya
in thread tr{}{} doesn't wanna work.. what am I doing wrong? by ultranerds

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.