Do you know if there is an alternative way to write:
$a = "\x{ae}";

Just for comparison, a couple of ways to do and not do it:

use utf8; use Encode; # for values below 0x100, the chars will always be 8-bit # ("use utf8;" doesn't help here) $s = "ABC\x{ae}XYZ"; info(1, $s); # would've been nice, but doesn't work either $s = "ABC\x{00ae}XYZ"; info(2, $s); # ...same problem with single chars $c = chr(0xae); info(3, $c); $c = chr(0x00ae); info(4, $c); # works for a single char $c = pack("U", 0x00ae); info(5, $c); # ...but gets a little unwieldy for strings $s = pack("U*", unpack("C*", "ABC\x{ae}XYZ")); info(6, $s); # works -- recommended $s = Encode::decode("iso-8859-1", "ABC\x{ae}XYZ"); info(7, $s); # produces a UTF-8 sequence, but with utf8 flag turned off $s = Encode::encode("utf-8", "ABC\x{ae}XYZ"); info(8, $s); # works $s = "ABC\x{ae}XYZ"; utf8::upgrade($s); info(9, $s); # like upgrade(), but with utf8 flag turned off $s = "ABC\x{ae}XYZ"; utf8::encode($s); info(10, $s); # doesn't work (is not supposed to... just for comparison) $s = "ABC\x{ae}XYZ"; utf8::decode($s); info(11, $s); # doesn't work - DON'T EVER DO THAT $s = "ABC\x{ae}XYZ"; Encode::_utf8_on($s); info(12, $s); sub info { my ($n, $s) = @_; printf "%2d: ", $n; print join(" ",unpack("(A2)*", unpack("H*",$s))), # hexdump "\t--> is ", utf8::is_utf8($s) ? "":"not ", "utf8\n"; }

prints:

1: 41 42 43 ae 58 59 5a --> is not utf8 2: 41 42 43 ae 58 59 5a --> is not utf8 3: ae --> is not utf8 4: ae --> is not utf8 5: c2 ae --> is utf8 6: 41 42 43 c2 ae 58 59 5a --> is utf8 7: 41 42 43 c2 ae 58 59 5a --> is utf8 8: 41 42 43 c2 ae 58 59 5a --> is not utf8 # wrong 9: 41 42 43 c2 ae 58 59 5a --> is utf8 10: 41 42 43 c2 ae 58 59 5a --> is not utf8 # wrong 11: 41 42 43 ae 58 59 5a --> is not utf8 12: 41 42 43 ae 58 59 5a --> is utf8 # WRONG

Confused? ;)

As to using use utf8;, this would work only if you've written your string literals in UTF-8 (not \x{...}), i.e. if you've been using a UTF-8 editor to compose the script...


In reply to Re^3: Why does perl not mark variable as utf-8? by almut
in thread Why does perl not mark variable as utf-8? by Anonymous Monk

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.