Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Archive::Zip - How to selectively copy files from one archive to another one?

by Mr. Muskrat (Canon)
on Aug 12, 2012 at 21:53 UTC ( [id://986981]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Archive::Zip - How to selectively copy files from one archive to another one?
in thread Archive::Zip - How to selectively copy files from one archive to another one?

It's all explained rather well in the docs. Archive::Zip

addFile is expecting a filename not an Archive::Zip::ZipFileMember object. Try this instead:

#!perl use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); # Include actual filenames in the next two lines my $oldfile = 'oldzip.zip'; my $newfile = 'newzip.zip'; my $oldzip = Archive::Zip->new(); $oldzip->read( $oldfile ) == AZ_OK or die 'read error'; print "$oldfile contains the following files:\n"; print " $_\n" for $oldzip->memberNames(); print "\n"; my $newzip = Archive::Zip->new(); my @wanted = $oldzip->membersMatching( '123.*\.xml' ); for my $member ( @wanted ) { print "Extracting ", $member->fileName(), " from $oldfile and addi +ng to $newfile\n"; $oldzip->extractMember( $member ); $newzip->addMember( $member ); } print "\n"; $newzip->writeToFileNamed( $newfile ) == AZ_OK or die 'error somewhere +'; print "$newfile contains the following files:\n"; print " $_\n" for $newzip->memberNames(); __END__ # Sample output oldzip.zip contains the following files: 123a.xml 123b.xml 234c.xml Extracting 123a.xml from oldzip.zip and adding to newzip.zip Extracting 123b.xml from oldzip.zip and adding to newzip.zip newzip.zip contains the following files: 123a.xml 123b.xml

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://986981]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-03-19 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found