🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.bazy-danych
Article #194499

Re: PostgreSQL - perl DBI problem z kodowaniem UTF8

#194499
From: hubert depesz lubaczewski
Date: Tue, 23 Jun 2015 11:09
36 lines
1944 bytes
On 2015-06-23, Czarek Grądys <czarekgr@wa.onet.pl> wrote:
> Skrypt mniej więcej taki:
> #!/usr/bin/perl
> use utf8;
> use DBI;
> use Config::Tiny;

Ja wiem, że długie, ale przeczytaj proszę:
https://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
pytanie, i pierwszą odpowiedź (tchrist'a).

Ja po tym po prostu mam taki "boilerplate" dla wszystkich skryptów
perlowych:

#v+
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
use v5.14;
use strict;
use warnings;
use warnings qw( FATAL utf8 );
use utf8;
use open qw( :std :utf8 );
use Unicode::Normalize qw( NFC );
use Unicode::Collate;
use Encode qw( decode );
if ( grep /\P{ASCII}/ => @ARGV ) {
    @ARGV = map { decode( 'UTF-8', $_ ) } @ARGV;
}
# If there is __DATA__,then uncomment next line:
# binmode( DATA, ':encoding(UTF-8)' );
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
#v-

To rozwiązuje większość problemów.

depesz
Technical Details
Message-ID: <6drn5c-rkp.ln1@depesz.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!plix.pl!newsfeed2.plix.pl!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
References: <558929cb$0$2191$65785112@news.neostrada.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!plix.pl!newsfeed2.plix.pl!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Newsgroups: pl.comp.bazy-danych
From: hubert depesz lubaczewski <depesz@depesz.com>
Subject: Re: PostgreSQL - perl DBI problem z kodowaniem UTF8
References: <558929cb$0$2191$65785112@news.neostrada.pl>
Organization: depesz Software
Reply-To: depesz@depesz.com
User-Agent: slrn/1.0.2 (Linux)
Mime-Version: 1.0
Date: Tue, 23 Jun 2015 13:09:58 +0200
Message-ID: <6drn5c-rkp.ln1@depesz.com>
Lines: 36
NNTP-Posting-Host: 83.28.237.87
X-Trace: 1435058404 unt-rea-a-02.news.neostrada.pl 27525 83.28.237.87:49233
X-Complaints-To: abuse@news.neostrada.pl
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit