in reply to Unicode problem with some letters

I think that your problem boils down to three questions:

What is my locale?
Do I need to use binmode?
How do I get the appropriate results?

Knowing when to use binmode can be prove to be a real challenge at times, so I put this script together to answer those questions.
#!/usr/bin/perl -l use strict; use warnings; use Encode; use Encode::Locale qw( $ENCODING_LOCALE ); use File::Util qw( needs_binmode ); if ( needs_binmode ne 0 ) { print "# ENCODING_LOCALE is $ENCODING_LOCALE"; print "# Needs binmode"; } if ( $ENCODING_LOCALE eq 'UTF-8' ) { my $str1 = "\xC3\xA0"; my $str2 = "\xD0\xBC"; print "$str1"; print "$str2"; } if( $ENCODING_LOCALE ne 'UTF-8' ) { binmode STDOUT, ':encoding(utf8)'; my $str1 = "\xC3\xA0"; my $str2 = "\xD0\xBC"; print "$str1"; print "$str2"; }
Encode::Locale and File::Util are required.

Replies are listed 'Best First'.
Re^2: Unicode problem with some letters
by OlegG (Monk) on Aug 22, 2011 at 15:06 UTC
    Looks portable. Thanks.