Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Unicode at Windows' cmd.exe

by tompagenet (Novice)
on Jul 13, 2008 at 15:39 UTC ( [id://697336]=perlquestion: print w/replies, xml ) Need Help??

tompagenet has asked for the wisdom of the Perl Monks concerning the following question:

I have tried outputting Unicode characters to cmd.exe. I have the font of cmd windows set to Lucinda. I've tried this:
binmode(STDOUT, ":utf8"); system('chcp 65001'); print "\x{016B} \n"; print "£ \n";
This is saved in a perl program in a UTF-8 encoded file. I have run this and this is the output I get on the screen:
Active code page: 65001 ū £
Why am I getting that "Â" before the pound sign? Any ideas how to fix it? Note that the ū *does* appear correctly as a u with a bar, but it won't display in this post. Tom

Replies are listed 'Best First'.
Re: Unicode at Windows' cmd.exe
by massa (Hermit) on Jul 13, 2008 at 16:25 UTC
    Your script is probably using UTF-8 (as the encoding of the body of the script). So, you must
    use utf8;
    I, personally (as a Brasilian that has pt_BR as native language), start all my scripts with:
    use strict; use warnings; use utf8; # I will write this script in UTF-8 use open qw(:std :locale); # All files to be open in the native cp use locale; # I want my string comparisons according to native locale
    This makes my I/O to be done in cp1252 in Windows, and in Latin1 or UTF-8 in linux. I edit my scripts in vim with UTF-8 encoding in both platforms.
    Update:I recently learned that
    use open qw(:std :locale);
    and
    use open qw(:locale);
    do the same thing.
    []s, HTH, Massa
      I think the dosbox uses cp8xx encodings not 12xx ones. That's an annoying problem for all non-latin1 AFAIK :p Dumb dos... And the code sample you gave does not seem to work for my locale (tr). All I get is this warning instead:
      Cannot figure out an encoding to use
        Heh, your OS is not passing the correct locale. You can switch :locale in the use open to:
        use open ':std', ':encoding(iso-8859-9)';
        (for example, if the encoding you use is that, ':encoding(cp857)' if not)...
        []s, HTH, Massa
Re: Unicode at Windows' cmd.exe
by Thelonius (Priest) on Jul 13, 2008 at 16:24 UTC
    Add "use utf8;" to the start of your program to tell perl that the file is in encoded in UTF-8.
Re: Unicode at Windows' cmd.exe
by Anonymous Monk on Nov 03, 2008 at 11:09 UTC
    ëÜìâäá

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://697336]
Approved by moritz
Front-paged by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-18 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found