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

Dear Masters,
I have list of gzip files:
file1.gz file2.gz file3.gz
Is there Perl ways to join or compressing these files into one gzip file (one batch file) without having to decompress them individually? Moreover we want to preserve the files in gzip format after unzipping the batch file.

In practice we will use this in a web database (CGI). Where the web will receive a query from user and list out all the files based on the query and present them in a batch file back to the user.

I understand that we can do:
cat file1.gz file2.gz file3.gz > allfiles.gz
However upon gunzipping allfiles.gz the files  file1.gz file2.gz file3.gz were not preserved in their existing gzip format.

---
neversaint and everlastingly indebted.......

Replies are listed 'Best First'.
Re: Perl Way To Gzipping/Joining Multiple Gzip Files
by anneli (Pilgrim) on Nov 04, 2011 at 07:44 UTC

    Is there Perl ways

    Not really, as this is just a question of compression and archival. gzip doesn't do file-separation; it's just stream compression. So if you cat the existing .gz files together, as you see, you get one file back.

    tar is made exclusively for putting multiple files together; have you considered taring the .gzs together? (You'd have .gz.tar instead of .tar.gz, kinda!)

    Or, try .zip or .rar with a zero compression setting (as you will probably incur a size gain trying to compress the already compressed .gzs).

Re: Perl Way To Gzipping/Joining Multiple Gzip Files
by Anonymous Monk on Nov 04, 2011 at 06:43 UTC

    gzip works the way it works, independent of perl, so this is not a perl question :)

    try stuffing the gzipped files into a zip file