I think I've got it now, but I still don't know how I can get this decimal value in Perl. If I pass a utf8 string to ord(), it gives me a value for each byte, not the double-byte character.

Only if perl doesn't know that the string really is utf8. If the string is coming from a data file, and you open that file without telling perl specifically what type of encoding to use for it, perl reads data from the file as bytes, and you need to decode() the string (using the Encode module) so that perl will see it properly converted/interpreted as utf8 characters, and the scalar variable holding the string will be flagged as such. Note the following:

# open an euc-jp file: open( $inp, "<:encoding(euc-jp)", "some_file.euc" ) or die "$!"; while (<$inp>) { # data will be decoded on input ... # so $_ will have its utf8 flag "on" and # s///, ord(), etc will use character semantics } # open a utf8 file: open( $inp, "<:utf8", "some_file.utf8" ) or die "$!"; while (<$inp>) { # data will be interpreted as utf8 on input ... # so $_ will have its utf8 flag "on" and... (same as above) }

If your string is based on some literal value in your perl script file, you have to make sure that the editor you use to compose the source code is saving the script as a utf8 file (and you probably need to put use utf8; in the script, so perl knows how to interpret the literal utf8 characters that it contains).


In reply to Re^5: iso-8859-1 code converter by graff
in thread iso-8859-1 code converter by GaijinPunch

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.