Debian lenny version packages
[pkg-perl] / deb-src / libarchive-zip-perl / libarchive-zip-perl-1.18 / examples / extract.pl
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.
6 #
7 # $Revision: 1.5 $
8 #
9 use strict;
10
11 my $dirName = 'extractTest';
12
13 use vars qw( $opt_j );
14 use Archive::Zip qw(:ERROR_CODES);
15 use Getopt::Std;
16
17 $opt_j = 0;
18 getopts('j');
19
20 if (@ARGV < 2)
21 {
22         die <<EOF
23         usage: perl extract.pl [-j] zipfile.zip filename [...]
24         if -j option given, discards paths.
25 EOF
26 }
27
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;
32
33 foreach my $memberName (@ARGV)
34 {
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;
40 }