note
Corion
<p>The order of decompressing and decoding matters. You want to first uncompress and <i>then</i> decode. If you want to cheat, you can use [mod://PerlIO::gzip]:</p>
<c>
my $in;
my $open_mode = '<:raw';
if ($filename=~/\.gz$/) {
$open_mode .= ':gzip';
}
$open_mode .= ':utf8';
open my $in, $open_mode, $filename or die "Can't read $filename: $!\n";
</c>
<p>If you want to stay with [mod://IO::Uncompress::Gunzip], I <i>think</i> the following should work, but I don't know if <c>->binmode()</c> also applies other encodings properly:</p>
<c>
my $in;
if ($filename=~/\.gz$/) {
$in = new IO::Uncompress::Gunzip $in, { AutoClose => 1 };
} else {
open $in, '<:raw', $filename or die "Can't read $filename: $!\n";
};
binmode $in, ':utf8';
</c>
11115120
11115120