in reply to Zipping Files

Here, without all the extraneous modules, is simple example code. You're not using the Archive::Zip module properly.

#!/usr/bin/perl use strict; use warnings; use File::Spec::Functions qw'catdir catfile'; use Archive::ZIP qw':ERROR_CODES :CONSTANTS'; # here's an example @chunks array my @chunks = qw(file1.txt file2.txt file3.txt); #example output file name: output.zip in HomeDir my $zip_file = catfile($ENV{HOME},'output.zip'); my $zip = Archive::Zip->new(); foreach my $file (@chunks) { my $member = $zip->addFile($file); #add fil +e $member->desiredCompressionMethod( COMPRESSION_DEFLATED ); #compres +s file } #write ZIP file to disk my $status = $zip->writeToFileNamed($zip_file); die "Unable to write to file '$zip_file' if $status != AZ_OK; #error c +heck

Note that I never open my own file handle, the module takes care of all that for me.

<radiant.matrix>
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

Replies are listed 'Best First'.
Re^2: Zipping Files
by pKai (Priest) on Jun 27, 2006 at 22:15 UTC

    ++ for straight forward adaption of some of the functions mentioned in the "SYNOPSIS" code from the Archive::Zip docs to the OP's need.

    Note that I never open my own file handle, the module takes care of all that for me.

    Of course, if he wants to he can use writeToFileHandle (see docs linked above) … the module provides this and a full wealth of other functions to read/write/create/manipulate Zip-Archives.