Skip to content

Instantly share code, notes, and snippets.

@mshock
Created November 27, 2012 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshock/4156726 to your computer and use it in GitHub Desktop.
Save mshock/4156726 to your computer and use it in GitHub Desktop.
Perl zip utility
#! perl -w
package ZipUtil;
use strict;
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
use Exporter 'import';
our @EXPORT = qw(unzip);
# for CLI
my ($zip_file, $out_file, $filter) = @ARGV;
unzip($zip_file, $out_file, $filter) if scalar @ARGV;
1;
# for importers
sub unzip {
my ($zip_file, $out_file, $filter) = @_;
my $zip = Archive::Zip->new($zip_file);
unless ($zip->extractTree($filter || '', $out_file) == AZ_OK) {
warn "unzip not successful: $!\n";
}
}
@volomike
Copy link

volomike commented Dec 3, 2015

Awesome. Waisted 2 hours trying different methods that work on older OSX (Snow Leopard) and it's default Perl for an installer I'm working on, and your code here was just the ticket to show me the fix. Why this isn't so well advertised and known for unzipping on Perl -- I'll never know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment