UTF-8-codierte Umlaute via print und warn ausgeben




Hallo allerseits,

beim Versuch, sowohl via print als auch via warn Umlaute auszugeben, bin
ich auf folgendes Verhalten bei meinem Ubuntu Linux 6.10 (mit Perl 5.8.8)
gestossen, das ich nicht ganz verstehe:

: johannes@ford:~/bin$ cat ./foo.pl # Terminal auf UTF-8 gestellt
: #!/usr/bin/perl
: use strict;
: use warnings;
: # use utf8;
: my $s = "öäüÖÄÜß\n";
: print $s;
: warn $s;
:
: johannes@ford:~/bin$ ./foo.pl
: öäüÖÄÜß
: öäüÖÄÜß
: johannes@ford:~/bin$ ./foo.pl # use utf8 wieder einkommentiert
: ��
: öäüÖÄÜß
: johannes@ford:~/bin$ ./foo.pl # Terminal auf ISO-8859-15 gestellt
: öäüÖÄÜß
: öÀÌÖÄÜß
: johannes@ford:~/bin$ ./foo.pl # ISO-8859-15 Terminal, use utf8 auskommentiert
: öÀÌÖÄÜß
: öÀÌÖÄÜß

Mich wundert daran,
1. dass ich ohne #use utf8 bereits eine vernuenftige Ausgabe bekomme.
2. dass mit #use utf8, je nach verwendeter Terminal-Einstellung entweder
die print- oder die warn-Ausgabe kaputt ist.

Fuer mich sieht das so aus, als wuerde ohne 'use utf8' der String
unveraendert aufs Terminal gekippt, waehrend mit 'use utf8' fuer die
Standardausgabe irgendwelche Magie (Umwandlung in ISO-8859-15-codierte
Zeichen) veranstaltet wird, die ich gern verstehen und beeinflussen
wuerde. STDERR unterliegt diesem Umwandlungszauber scheinbar nicht.

Unter Windows/Cygwin im Cygwin-Terminal mit Cygwins Perl (5.8.7):

: ~/Perl$ cat ./foo.pl # im "Cygwin-Terminal"
: #!/usr/bin/perl
: use strict;
: use warnings;
: # use utf8;
: my $s = "Ã-Ã"ÃoöäüÃY\n";
: print $s;
: warn $s;
: ~/Perl$ ./foo.pl
: Ã-Ã"ÃoöäüÃY
: Ã-Ã"ÃoöäüÃY
: ~/Perl$ ./foo.pl # mit einkommentiertem use utf8
: ÖÄÜöäüß
: Ã-Ã"ÃoöäüÃY
: ~/Perl$ /cygdrive/c/WINNT/system32/chcp.com 1252
: Aktive Codepage: 1252.
: ~/Perl$ ./foo.pl
: ÖÄÜöäüß
: ÖÄÜöäüß
: ~/Perl$ ./foo.pl # wieder mit auskommentierem use utf8
: ÖÄÜöäüß
: ÖÄÜöäüß
: ~/Perl$

Im UTF-8-Xterm funktioniert die Umlautausgabe mit print und warn,
wenn 'use utf8' auskommentiert ist. Wenn es nicht auskommentiert ist,
funktioniert nur warn. Die Ausgabe des Xterms laesst sich leider nur
stark verlustbehaftet in den Editor uebernehmen, deswegen spare ich
sie mir an dieser Stelle.

Mit ActivePerl 5.8.8 aus cmd.exe aufgerufen erhalte ich:

: C:\home\loewjoha\Perl>type foo.pl
: #!/usr/bin/perl
: use strict;
: use warnings;
: # use utf8;
: my $s = "├û├ä├£├Â├ñ├╝├ƒ\n";
: print $s;
: warn $s;
:
: C:\home\loewjoha\Perl>perl foo.pl
: ├û├ä├£├Â├ñ├╝├ƒ
: ├û├ä├£├Â├ñ├╝├ƒ
:
: C:\home\loewjoha\Perl>perl foo.pl ! mit use utf8
: Í─▄÷õ³▀
: ├û├ä├£├Â├ñ├╝├ƒ
:
: C:\home\loewjoha\Perl>chcp 1252
: Aktive Codepage: 1252.
:
: C:\home\loewjoha\Perl>perl foo.pl
: ÖÄÜöäüß
: ÖÄÜöäüß
:
: C:\home\loewjoha\Perl>perl foo.pl ! ohne use utf8
: ÖÄÜöäüß
: ÖÄÜöäüß


Die Manpage zu utf8 verstehe ich so, dass ich mit dem Pragma erklaere,
dass mein Script UTF-8-codiert ist, und dass, wenn UTF-8 irgendwann das
"standard source format" wird, es (das Pragma) zumindest keinen Schaden
anrichtet. Mir scheint, der zweite foo.pl-Aufruf unter Linux (und im
UTF-8-Xterm unter Cygwin) widerspricht dieser Aussage.

Eigentlich bin ich auf der Suche nach einer Moeglichkeit, ein Script
(am liebsten UTF-8-codiert) so zu schreiben, dass es unter Linux, unter
Cygwin Perl (im xterm und im "gewoehnlichen" Cygwin-Terminal) und auch
unter ActivePerl (Windows, cmd.exe) sowohl via print als auch via warn
umlauthaltige Strings ausgeben kann.

Bei Windows/ActivePerl/cmd.exe habe ich, wie man sieht, noch gar keine
Loesung fuer das Umlautausgabeproblem gefunden. Hier waere mir auch
schon mit einer Windows-only-Loesung geholfen. Etwas portables waere
mir natuerlich lieber.

Ich freue mich ueber jede Erklaerung, die Licht in die Dunkle Kunst der
Umlautausgabe bringt.

Herzliche Gruesse

Johannes
.



Relevant Pages

  • Re: LD_LIBRARY_PATH on x86_64 linux
    ... I imagine you also have to take in to account whether you are using 64bit OS vs 32 bit perl, etc. etc. I've always dealt with this issue on my Sun boxes and resorted to using a wrapper script. ... My environment generally needs to be different for launching other oracle applications, so this way I don't break other things. ... Subject: LD_LIBRARY_PATH on x86_64 linux ... on other Linux platforms, too. ...
    (perl.dbi.users)
  • Re: Demand of PF CLI
    ... >> using the PF APIs directly, or providing such access in perl, python, ... >> style approach was taken to embrace other firewall solutions. ... > you mean this module could work for Linux iptables too. ... There is Linux's iptables, ipf on NetBSD and Solaris, ...
    (comp.unix.bsd.openbsd.misc)
  • Re: Should fresh graduates be good at platform specific libraries?
    ... curious enough about linux to setup a linux box. ... unix-like shell environment and have not discovered perl. ... kind of stuff that says you will not be passionate about this career. ... real regular expressions in an Automata Theory course. ...
    (comp.programming)
  • Re: Need help installing WWW-Search-Ebay-2.193 Module...
    ... One of the O'Reilly Books has a script that calls this ... >>languages (which are far easier to program in under Linux than under ... > perl Makefile.PL ... >>ActivePerl for Linux under Cygwin ...
    (comp.lang.perl.misc)