pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Verite <daniel@manitou-mail.org>
To: Christoph Moench-Tegeder <cmt@burggraben.net>
Cc: Matthias Apitz <guru@unixarea.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to the server
Date: Sat, 12 Oct 2019 15:52:27 +0200
Message-ID: <69f69a9e-78eb-4448-b820-533b581c8677@manitou-mail.org> (raw)
In-Reply-To: <20191012131424.GA2452@elch.exwg.net>

	Christoph Moench-Tegeder wrote:

> And then it doesn't know that your terminal expects UTF-8 (perl
> just dumps the binary string here), because you didn't tell it:
> "binmode(STDOUT, ':encoding(utf8)')" would fix that.

Or use perl -C, so that it gets that from the environment.

 From https://perldoc.perl.org/perlrun.html :

 -C on its own (not followed by any number or option list), or the
 empty string "" for the PERL_UNICODE environment variable, has the
 same effect as -CSDL. In other words, the standard I/O handles and
 the default open() layer are UTF-8-fied but only if the locale
 environment variables indicate a UTF-8 locale.

Now for what the OP is doing, I'd suggest to use Dump() from the
Devel::Peek module instead of print.

To see the difference between a literal "ä" and "\xc3\xa4" from the
point of view of Perl:

   use Devel::Peek;
   use utf8;

   $str = "\xc3\xa4";
   Dump($str);

   $str = "ä";
   Dump($str);

Result:

SV = PV(0x55af63beeda0) at 0x55af63c185d0
  REFCNT = 1
  FLAGS = (POK,IsCOW,pPOK)
  PV = 0x55af63c3c230 "\303\244"\0
  CUR = 2
  LEN = 10
  COW_REFCNT = 1
SV = PV(0x55af63beeda0) at 0x55af63c185d0
  REFCNT = 1
  FLAGS = (POK,IsCOW,pPOK,UTF8)
  PV = 0x55af63c58dc0 "\303\244"\0 [UTF8 "\x{e4}"]
  CUR = 2
  LEN = 10
  COW_REFCNT = 1



Best regards,
-- 
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite





view thread (7+ messages)

Message-ID: <69f69a9e-78eb-4448-b820-533b581c8677@manitou-mail.org>
Permalink:  ../69f69a9e-78eb-4448-b820-533b581c8677@manitou-mail.org/
Also on:    postgresql.org/message-id/69f69a9e-78eb-4448-b820-533b581c8677@manitou-mail.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: daniel@manitou-mail.org, cmt@burggraben.net, guru@unixarea.de
  Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to the server
  In-Reply-To: <69f69a9e-78eb-4448-b820-533b581c8677@manitou-mail.org>
  References: <20191012131424.GA2452@elch.exwg.net> <69f69a9e-78eb-4448-b820-533b581c8677@manitou-mail.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox