🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.perl
2 messages
2 total messages Started by stas53 Wed, 19 Jan 2011 12:58
UTF-8 w STDERR
#52159
Author: stas53
Date: Wed, 19 Jan 2011 12:58
22 lines
1644 bytes
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ć ?

Pozdrawiam,

Stanisław
Re: UTF-8 w STDERR
#52165
Author: Szymon Sokół
Date: Wed, 19 Jan 2011 15:20
57 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads