Hi to all !

I thought I'd understood a little of character encoding ... But now I'm completely lost :

Given these 2 minimal "scripts" : (you should see 5 e-accutes in the strings )

cat miniUTF8.pl print 'ייייי ' , length 'ייייי' , "\n"; cat miniUTF8-2.pl use utf8; print 'ייייי' , length 'ייייי' , "\n";
When I run the first one, I see 5 splendid e-acutes, but length is said 10

When I run the second one, I see 5 question marks, but the length is 5

All this is done on a macbook pro, perl 5.14.2, locale on next lines, in the terminal window. The preferences of terminal are set for "UTF-8" encoding (that's why cat give good results)

LANG="fr_FR.UTF-8" LC_COLLATE="fr_FR.UTF-8" LC_CTYPE="fr_FR.UTF-8" LC_MESSAGES="fr_FR.UTF-8" LC_MONETARY="fr_FR.UTF-8" LC_NUMERIC="fr_FR.UTF-8" LC_TIME="fr_FR.UTF-8" LC_ALL=
Next line : an hexadecimal dump of the "print" line: One clearly sees it's utf8 encoded (0xa9c3 is e-acute)

od -x miniUTF8.pl 0000000 7270 6e69 2074 c327 c3a9 c3a9 c3a9 c +3a9 0000020 20a9 2027 2c09 6c20 6e65 7467 2068 c +327 0000040 c3a9 c3a9 c3a9 c3a9 27a9 2c20 2020 5 +c22 0000060 226e 0a3b + 0000064
Any idea or explanation is welcome !!

Didier


In reply to minimalist perl-utf8 question by didess

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.