Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: unpacking .gz from perl

by ferreira (Chaplain)
on Feb 16, 2008 at 20:01 UTC ( #668344=note: print w/replies, xml ) Need Help??

in reply to unpacking .gz from perl

For most uses, you'll probably be satisfied with the solutions above, where you decompress the .gz file into memory and "operates" on the uncompressed content as you wish.

But if you need to deal with really big files or if the operations you'll need to apply prefer the content in a file (eg. when you need to pass it to external programs), you can do it with a combination of Archive::Extract and File::Temp. The following code is such an example:

use File::Temp (); use Archive::Extract (); for my $gz ( @ARGV ) { my $tmp = File::Temp->new(); my $ae = Archive::Extract->new( archive => $gz ); my $ok = $ae->extract( to => $tmp->filename ); die $ae->error unless $ok; # do what you want to the uncompressed content in the # file named $tmp->filename ... # at the end of the scope, $tmp vanishes }

This code has the bonus of working with other compressed types, like .bz2, .Z and even .lzma with the latest release of Archive::Extract. Even more, because this module may also extract archives with multiple files like .tar.gz, .zip, etc.

Replies are listed 'Best First'.
Re^2: unpacking .gz from perl
by Anonymous Monk on Dec 30, 2012 at 04:24 UTC

    did this code work for u.When i tried its showing an error like "It looks like you don't have a C compiler on your PATH, so you will not be able to compile C or XS extension modules. You can install GCC from the MinGW package using the Perl Package Manager by running: ppm install MinGW"

    I tried installing using the above command.But installation is getting failed

      When i tried its showing an error like

      It is not only an error message, it is instructions to overcome the error!!!!!!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://668344]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2023-01-28 06:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found