How do I read a GZipped UTF-8 file from Perl on Windows?

D

DmitryB

Hi, folks,

I'm looking for a way to read and write *.gz text files in UTF8
encoding on windows (ActivePerl, gzip Perl::IO layer is not
available). I've tried naive IO::Zlib stuff like this:

tie *OUTPUTFILE, "IO::Zlib", $outputFile, "wb" or die "Could not open
$outputFile for reading";
binmode(OUTPUTFILE, ":utf8");

Unfortunately this doesn't work, the error is:

"Not a GLOB reference at c:/bin/perl/lib/IO/Zlib.pm line 566."


Basically, the goal is to layer utf8 on top of zlib or achieve a
similar result using other means. Again, keep in mind, I can't just
say "gzip" in open() because that's not available.

Does anyone have any pointers?

Thanks.
 
D

DmitryB

Hi, folks,

I'm looking for a way to read and write *.gz text files in UTF8
encoding on windows (ActivePerl, gzip Perl::IO layer is not
available). I've tried naive IO::Zlib stuff like this:

tie *OUTPUTFILE, "IO::Zlib", $outputFile, "wb" or die "Could not open
$outputFile for reading";
binmode(OUTPUTFILE, ":utf8");

Unfortunately this doesn't work, the error is:

"Not a GLOB reference at c:/bin/perl/lib/IO/Zlib.pm line 566."

Basically, the goal is to layer utf8 on top of zlib or achieve a
similar result using other means. Again, keep in mind, I can't just
say "gzip" in open() because that's not available.

Does anyone have any pointers?

Thanks.

I just ended up using out of process piped gzip. Works pretty good if
you don't forget to quote the filename. :)
 
M

Michele Dondi

I just ended up using out of process piped gzip. Works pretty good if
you don't forget to quote the filename. :)

Hard to say without seeing any code, but I suspect you're using
something like

open my $fh, '-|', 'gzip -d "filename.gz"' or die $!;

In that case, you can also give the arguments to gzip in LIST form as

open my $fh, '-|', 'gzip' => '-d', 'filename.gz' or die $!;

which may be useful.


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top