in reply to Checking if a file is present in a ZIP archive

Sometimes, a CPAN dist will contain additional documentation in a POD file separate from the main module file. From the Archive::Zip::FAQ: How to test file integrity?
Q: How can Archive::Zip can test the validity of a Zip file? A: There are two ready-to-use utilities in the examples directory that ca +n be used to test file integrity, or that you can use as examples for your own code: examples/zipcheck.pl shows how to use an attempted extraction to test +a file.

The example script uses eval and:

Archive::Zip::setErrorHandler( sub { warn shift() } );

When I run zipcheck.pl on a file which I know is not a zip file, I only get one message:

format error: can't find EOCD signature

Replies are listed 'Best First'.
Re^2: Checking if a file is present in a ZIP archive
by bontchev (Sexton) on Mar 25, 2011 at 20:32 UTC
    I use ActivePerl in WinXP and there is no examples directory in the Archive::ZIP package.

        Thanks!

        OK, problem solved. The trick was to suppress the error reporting from the package with

        Archive::Zip::setErrorHandler (sub { });

        before trying to process the file, as they do in this example (well, almost, they still print the first warning there, but the idea was clear). Then just skip the file, if the attempt to read it does not return AZ_OK.

      Just set the error handler to empty sub to avoid printing the warnings.