pspillai has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to read .gz files for which I tried to use Archive::Zip. Is there any other module which can serve the same purpose? Thank you. P

Replies are listed 'Best First'.
Re: Reading .gz files.
by locked_user sundialsvc4 (Abbot) on Mar 23, 2011 at 19:11 UTC

    A “gzip” file and a “zip” file are not quite the same.   Compress::Zlib should be the appropriate module for your purposes.   (A search for “compress gzip” at http://search.cpan.org provides plenty of working examples.

      Thanks. That works fine. There's some issue with writing the results to a zipped file. I used a code ------ my $gz=gzopen("test.vcf.gz","wb"); $gz -> gzwrite(@dose); $gz ->gzclose; ------------------ What my intention was to get a file with contents of @dose in a compressed .gz file - test.vcf.gz What's wrong in this? I am getting a file test.vcf.gz which has just one line ! Thank you. P.
Re: Reading .gz files.
by toolic (Bishop) on Mar 23, 2011 at 18:48 UTC
    The SEE ALSO section of the POD for Archive::Zip links to these other modules, which may do something similar:
    Compress::Raw::Zlib, Archive::Tar, Archive::Extract

    Are you having a problem with Archive::Zip which you care to discuss?

      Hi, Thank you for the response. I tried to read file using Archive::Zip code looks like -- #!/usr/bin/perl use warnings; use strict; use Archive::Zip qw( :ERROR_CODES ); # Read a Zip file my $somezip = Archive::Zip->new(); my $fname = $ARGV[0]; unless ( $somezip->read( "$fname" ) == AZ_OK ) { die 'read error'; -------------------------------- The code is throwing en error which says- 'format error: Can't find EOCD signature' File is a .gz file. Do you have an idea what this error is about? Thank you.
Re: Reading .gz files.
by Anonymous Monk on Mar 23, 2011 at 19:26 UTC
    use Archive::Extract; ### build an Archive::Extract object ### my $ae = Archive::Extract->new( archive => 'foo.tgz' ); ### extract to cwd() ### my $ok = $ae->extract; ### extract to /tmp ### my $ok = $ae->extract( to => '/tmp' ); ### what if something went wrong? my $ok = $ae->extract or die $ae->error; ...

      Perfecto...

      I neglected to say that modules like Compress::Zlib are low-level functionality, upon which other, higher-level CPAN modules have been constructed.   Search for the CPAN module which most closely matches what you are trying to achieve, and let them use the lower level routines on your behalf.