in reply to Determine encoding of STDOUT

If the character encoding can be reliably extracted from the locale, open helps:

use open IO => ':locale';

But as tchrist said, you'll be happier with all-UTF-8 environments in the long run.

Replies are listed 'Best First'.
Re^2: Determine encoding of STDOUT
by CountZero (Bishop) on May 04, 2011 at 18:49 UTC
    When I run the following program on my Windows XP Pro box, it reports French_Belgium.1252:
    use Modern::Perl; use POSIX qw(locale_h); my $old_locale = setlocale(LC_CTYPE); say $old_locale;

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^2: Determine encoding of STDOUT
by Dirk80 (Pilgrim) on May 04, 2011 at 13:47 UTC

    It seems that the character encoding cannot be extracted from locale because I get the following error message:

    Cannot figure out an encoding to use at test.pl line 9

      So you need some other mechanism for signaling encoding. For example have the user provide some environment variables if the encoding is different than UTF-8.

Re^2: Determine encoding of STDOUT
by ikegami (Patriarch) on May 04, 2011 at 17:03 UTC
    Doesn't work. One would have to call WinAPI function GetACP