Please tell me that I'm missing something here.
My goals are:
Text read from stdin, written to stdout and arguments on the commandline should respect the current user locale.
Source code is in a fixed format (usually utf8) Files/pipes should be in the format I specify.
My example script:
Let's run it:#!/usr/bin/perl use strict; use warnings; use utf8; use open qw(:std :locale); open (my $in,"-|:encoding(utf8)","echo \xc3\xb6") || die ; my $line=<$in>; chomp($line); print "I read a line, that is ",length($line)," chars long.\n"; print "That line is: ",$line,"\n"; $line =~ s/ö/o/; print "That line in ascii is: $line\n";
The second case fails horribly. I have no idea why. If I comment the "use open" line, it (of course) fails printing the umlauts on any utf-8 terminalkaroshi:~>LC_CTYPE=de_DE.UTF-8 ./u8demo.pl I read a line, that is 1 chars long. That line is: ö That line in ascii is: o karoshi:~>LC_CTYPE=C ./u8demo.pl ascii "\xC3" does not map to Unicode at ./u8demo.pl line 12. ascii "\xB6" does not map to Unicode at ./u8demo.pl line 12. I read a line, that is 8 chars long. That line is: \xC3\xB6 That line in ascii is: \xC3\xB6
Is there a way to get perl to "do the right thing"?karoshi:~>./u8demo.pl I read a line, that is 1 chars long. That line is: � That line in ascii is: o