Oh, monks, I think I have tried everything, but the solution....

I'm retrieving data from a PostgreSQL database, using Perl DBI.

The data is to be printed on mail labels, using Postscript::MailLabels, which is an excellent module, but apparently, it needs Latin1-encoded data to work.

Natively, data in the DB is UNICODE encoded, I assume that means UTF8. So, the problem is to reencode the data into Latin1.

There are, apparently, many modules to do this, Unicode::Map, Unicode::Map8, Unicode::MapUTF8 and Unicode::String, but if I use these, most of them apparently just strips off the Norwegian characters (which I'm interested in), or in some cases, I have lost the whole string.

Probably, I'm just using it wrongly.... Digesting the fine manuals have been attempted, for example, I have set

Unicode::String->stringify_as("utf8");

which is supposed to tell the module that the strings it gets are UTF8. But it doesn't hear my prayers...

Finally, I've tried to let PostgreSQL do the work, by going

$rv = $dbh->do("SET CLIENT_ENCODING TO 'LATIN1';");

but, apparently, the output I get is 7 bits, as ø is mapped to x (IIRC).

Wise ones, surely you have been in the same position when you were young, how do I do this right?


In reply to Encoding of DBI PostgreSQL output by Kjetil

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.