Updated perl minimum version to 5.004. Replaced three-argument open with
[archive-zip.git] / examples / extract.pl
blob4425ab4bd16df88a580c9714dfd5cf84b9033a51
1 #!/bin/perl -w
2 # Extracts the named files into 'extractTest' subdir
3 # usage:
4 # perl extract.pl [-j] zipfile.zip filename [...]
5 # if -j option given, discards paths.
7 # $Revision: 1.5 $
9 use strict;
11 my $dirName = 'extractTest';
13 use vars qw( $opt_j );
14 use Archive::Zip qw(:ERROR_CODES);
15 use Getopt::Std;
17 $opt_j = 0;
18 getopts('j');
20 if (@ARGV < 2)
22 die <<EOF
23 usage: perl extract.pl [-j] zipfile.zip filename [...]
24 if -j option given, discards paths.
25 EOF
28 my $zip = Archive::Zip->new();
29 my $zipName = shift(@ARGV);
30 my $status = $zip->read( $zipName );
31 die "Read of $zipName failed\n" if $status != AZ_OK;
33 foreach my $memberName (@ARGV)
35 print "Extracting $memberName\n";
36 $status = $opt_j
37 ? $zip->extractMemberWithoutPaths($memberName)
38 : $zip->extractMember($memberName);
39 die "Extracting $memberName from $zipName failed\n" if $status != AZ_OK;