Perl Module - Archive::Zip

From Torben's Wiki

[1]

use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

Create zip and add stuff

my $zip = Archive::Zip->new(); # Create a Zip file
foreach my $i (@list) {
  if (-d $i)    { $zip->addTree($i,$i);}
  elsif (-f $i) { $zip->addFile($i);}
}
die unless ( $zip->writeToFileNamed($newZipFilename) == AZ_OK );

Extract a single file from zip archiv

my $zip = Archive::Zip->new();
die unless ( $zip->read( $templatefilename ) == AZ_OK );
$zip->extractMember( $fileNameToExtract );

Remove a file from zip archiv

my $zip = Archive::Zip->new();
die unless ( $zip->read( $newZipFilename ) == AZ_OK );
my $member = $zip->memberNamed( $fileToExtract );
$zip-> removeMember ($member);
die unless ($zip->overwrite() == AZ_OK); # save
unlink $fileToExtract;
push @ODPs, $newZipFilename;