Article View: pl.comp.lang.perl
Article #52165Re: UTF-8 w STDERR
From: Szymon Sokół
Date: Wed, 19 Jan 2011 15:20
Date: Wed, 19 Jan 2011 15:20
57 lines
3254 bytes
3254 bytes
On Wed, 19 Jan 2011 04:58:12 -0800 (PST), stas53 wrote:
> Cześć,
>
> Czy można zachęcić PERLa do pisania do STDERR w UTF-8 ?
> Przykład dość minimalny:
>
> #!perl -w
> use strict;
> use encoding 'utf8';
>
> my $some_norwegian_chars = 'åäéèöóøüÄÅÖØæ';
>
> print STDOUT $some_norwegian_chars, "\n";
> print STDERR $some_norwegian_chars, "\n";
>
> wypisuje (Windows) ok do STDOUT ale do STDERR stosuje jakąś dziwną
> konwersję.
> Czy trzeba użyc jakiegoś dodatkowego zaklęcia, czy też kodowaniem
> STDERR nie daje się manipulować ?
Manual (perldoc encoding) dość wyraźnie o tym mówi:
use encoding [ENCNAME] ;
Sets the script encoding to ENCNAME. And unless ${^UNICODE} exists and non-zero,
PerlIO layers of STDIN and STDOUT are set to ":encoding(ENCNAME)".
Note that STDERR WILL NOT be changed.
Also note that non-STD file handles remain unaffected. Use "use open" or "binmode" to
change layers of those.
Nie wiem, jak pod Windows, pod Unixem można załatwić sprawę dwojako - albo z użyciem opcji -C:
I STDIN is assumed to be in UTF-8
O STDOUT will be in UTF-8
E STDERR will be in UTF-8
S I + O + E
i UTF-8 is the default PerlIO layer for input streams
o UTF-8 is the default PerlIO layer for output streams
D i + o
(co za tym idzie, ja używam zwykle -CSD), albo w kodzie jawnie wskazać, że
STDERR też ma być w UTF-8:
use open IO => ':utf8';
use open ':std';
(patrz perldoc open - ta pierwsza opcja powoduje, że wszystkie strumienie
poza standardowymi są w UTF-8, a druga - że standardowe, tj. STDIN, STDOUT,
STDERR, również)
--
Szymon Sokół (SS316-RIPE) -- Network Manager B
Computer Center, AGH - University of Science and Technology, Cracow, Poland O
http://home.agh.edu.pl/szymon/ PGP key id: RSA: 0x2ABE016B, DSS: 0xF9289982 F
Free speech includes the right not to listen, if not interested -- Heinlein H
Technical Details
Message-ID:
<sq1g52kq8xbb.dlg@falcon.sloth.hell.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!.POSTED!dustpuppy.sloth.hell.pl!not-for-mailReferences:
<94fde7d7-eeb3-44a9-966f-711ecf92b115@r19g2000prm.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!.POSTED!dustpuppy.sloth.hell.pl!not-for-mail
From: Szymon Sokół
<szymon@bastard.operator.from.hell.pl>
Newsgroups: pl.comp.lang.perl
Subject: Re: UTF-8 w STDERR
Date: Wed, 19 Jan 2011 16:20:43 +0100
Organization: Guy Fawkes Society
Lines: 57
Sender: szymon@news.agh.edu.pl
Message-ID: <sq1g52kq8xbb.dlg@falcon.sloth.hell.pl>
References: <94fde7d7-eeb3-44a9-966f-711ecf92b115@r19g2000prm.googlegroups.com>
NNTP-Posting-Host: 89-78-159-131.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: news.agh.edu.pl 1295450667 18321 89.78.159.131 (19 Jan 2011 15:24:27 GMT)
X-Complaints-To: abuse@agh.edu.pl
NNTP-Posting-Date: Wed, 19 Jan 2011 15:24:27 +0000 (UTC)
User-Agent: 40tude_Dialog/2.0.15.1 Hamster/2.1.0.11
X-Face: xic?6f"rD)k-tM.]L]A6l4W7_aGt({}&{D,hiRI.8cPtf,1F.w@Qkl!vr23o1UY-BfXO$p< hk5>ijB?eBy)?!C<@)+%U\&`1X)MJ>.i.qgkY]4mvL62j<|xJRG/5:7:l8q]x;v!)Bz^r/!yG8DxoD -@fnC,g]BAXj
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit