Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: unpacking .gz from perl by ferreira
in thread unpacking .gz from perl by karpatov

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found