in reply to Lost in compressed encodings
The order of decompressing and decoding matters. You want to first uncompress and then decode. If you want to cheat, you can use PerlIO::gzip:
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";
If you want to stay with IO::Uncompress::Gunzip, I think the following should work, but I don't know if ->binmode() also applies other encodings properly:
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';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Lost in compressed encodings
by Skeeve (Parson) on Apr 06, 2020 at 08:53 UTC | |
by Corion (Patriarch) on Apr 06, 2020 at 08:59 UTC | |
by Skeeve (Parson) on Apr 06, 2020 at 09:19 UTC | |
by Tux (Canon) on Apr 06, 2020 at 10:49 UTC |