utf8 odd behavior with Gtk2



Hi,
I've been trying to figure out unicode, and came across
an odd behavior, which caused me hours of head scratching.

The following code will take a unicode $ARGV[0] from the commandline,
and do things with it, like search or whatever, but in this simple example
it is not important.

What you will notice, or I do with perl 5.14.1, is that the placement
of the "use utf8::all" changes what is decoded properly.  If that use line
comes before the Gtk2 modules, it dosn't decode input. If placed after, it
works fine.  Furthermore, if you comment out the Gtk2 modules, it works
right.

The utf8::all module is pretty simple, as it just puts utf8 layers on all std*,
filehandles, and decodes @ARGV.

It would seem that putting it before would be where it would work
properly, but it's the opposite.

Needless to say, this has caused me much confusion, as I couldn't figure
out why I needed to decode @ARGV manually, even if I used utf8::all.

Can anyone explain why this occurs?

0m,
zentara


See script below.
####################################
Commandline:  ./vgrep æ

Good output:   argv-> æ 
                     search-> æ

Bad output:     argv-> ÃÂ 
                     search-> ÃÂ


####################################

#!/usr/bin/perl 
use warnings;
use strict;

#use utf8::all;  # placed here the decoding dosn't work right

use Gtk2 -init;     # commenting out Gtk2 modules fixes problem
use Glib qw(FALSE TRUE);
use Gtk2::Pango;

use Encode qw(decode);

use utf8::all;  #placed here, the decoding works properly

$|++;

my $search_str = $ARGV[0];
$search_str ||= undef;

print "argv-> @ARGV \n";

print "search-> $search_str\n";
__END__




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]