I would support the earlier advice of the esteemed monks to use Archive::Zip module as it provides a fairly easy and straightforward way to zip files.
Here is a function that I use in my scripts (it might be not the best way to do it, but it works...)
sub ZipFile($)
{
my $fname = @_[0];
my $error = 0;
my $zipfile = $fname.'.zip'; #Update filename, add .ZIP at the end
my $zip = Archive::Zip -> new();
my $member = $zip->memberNamed( $fname );
if ($member eq undef) #No existing zip file with the file inside
{
$member = $zip->addFile( $fname ) or $error = 1; #Add file to ZI
+P archive
push @ERRORS, "Unable to zip $fname: $!\n" if $error;
LogError() if $error;
}
$member -> desiredCompressionLevel( 9 );
my $status = $zip -> overwriteAs($zipfile);
push @LOG, "$fname compressed (zipped) successfully\n";
return $zipfile; #Return updated filename
}
The function attempts to create a new .ZIP file, and 'add' a text file into the archive, thereby doing the same thing that you do when using Winzip to compress the file.
Hope this helps :)
--------------------------------
An idea is not responsible for the people who believe in it...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.