Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm completely lost in encodings :(

I'm reading data using LWP. When the data contains umlauts, things start to get weird and I get lost.

As the whole script is already very complex, let me try to give examples first before I start thinking about an example script.

For the example I use perl debugger. <&p>

After reading my data one of the strings looks like this:

DB<11> x $str 0 'Künzler' DB<12> x Encode::is_utf8($str) 0 '' DB<13> x length($str) 0 8 DB<14> x substr($str,0,3) 0 'Kü'

So I think my issue already starts here as the data I read is displayed correctly but perl treats it as bytes.

I do not know what to do with that string so that perl handles it correctly.

DB<20> x Encode::decode('utf8', $str) 0 'K?nzler'

(It was the Questionmark on a square that was displayed). That seemed wrong, but when I tested by reading from an utf-8 file opening it with '<:utf8' I got the same result, so obviously it's correct that way.

So as a test I changed my string here by decoding it as utf8.

In the next step, the string is handed to MIME::Lite::TT::HTML and by that to Text::Table. Finally it's send to me by mail.

When I look at the mail's source, the umlaut is (quoted printable) represented by '=FC' and, unfortunately, displayed as a questionmark in a square :(

I know I should have some sample code, and I will try to write some, but I hoped that in the meantime someone here with more experience already has a hint for me, where to debug further or how to fix it.

As far as I know, Text::Table requires perl strings to properly format tables. But shouldn't my string be a perl string when decoded?

Many thanks in advance.


In reply to Lost in encodings by Skeeve

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (6)
    As of 2021-03-04 18:52 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (107 votes). Check out past polls.