2

I need to search for a string in a zip archive containing multiple text files. How can I use perl Archive::Zip to do that? Also, what other module can it, if any?

My basic requirement is to find a particular text file in zipped archive which contains a given string.

3

1 Answer 1

2

Just a simple example how to iterate over all files in a zip,

use strict;
use Archive::Zip;
my ($path, $filename) = ('c:\\temp\\', 'many_filez.zip'); #try / instead of \\?
my $zip = Archive::Zip->new($path.$filename);
unless ($zip) {
    die dump "cannot open '$path' + '$filename'" 
}
#find only css-files
my @members = $zip->membersMatching('.*\.css');
foreach my $member (@members) {
    my $file_content = $zip->contents($member );
    if ($file_content =~ /text to look for/ ) {
        print "\n $member->{fileName} did have a match";
    }        
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.