I am using perl's AWP user agent to retreive data from the web and am having an awful time dealing with asian characters and other multibyte monstrosities.

Basically, I think it all boils down to what is going on in about three lines of code:
#$ua "a new user agent" #$req "a request to a website" #$res "a response to the request" $res = $ua->get($req); if($res->is_success){ $out = $res->content; print $out."\n"; }

My api works fine for latin character based languages, but fouls up horribly when it encounters asian characters - Japanese or Chinese Kanji, or Korean's Hangul alphabet. Instead of returning a nice string of readable characters, $out (or $res I'm not sure which) returns a string of octets corresponding to the individual bytes for these multibyte characters. This alone would not be too awful in and of itself, but in addition, those characters which happen to have alter-egos in the ASCII character set, i.e. those octets which can by properly represented as a single ASCII octet, are being converted to their single byte representation. This means that a single Kanji character gets split into two octets, say \304\211 (fictional!) and the \211 gets converted to a double quote " so that the final output for my script looks like \304". When I try to convert this back to multibyte characters I obviously get garbage. I'd like to know: at what point is perl carrying out this conversion process, and how can I intervene to make it do what I want - that is either not interpret ANY octets, or ideally print out sensible input. I will keep looking for a solution on my own, but I would greatly appreciate any thoughts. Encoding Hell.

In reply to Encoding Hell by kettle

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.