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

1) From the documentation:
my $zip = Archive::Zip->new( 'xyz.zip' );
If a filename argument is passed and the read fails for any reason, new will return undef.
So, my $zip = Archive::Zip->new($file) or die "$file cannot be opened by zip\n" should do. The barfed bunch are not errors but warnings.

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:35 UTC
    The problem is not that the file cannot be read. The file can be read just fine. However, if it happens not to be a ZIP archive, the Archive::ZIP package spews half a screen of errors from various parts of itself, essentially complaining about the missing signature and going downhill from there.
      Then find a way to turn those warnings into a die, for eval; for example by temporarily setting $SIG{__WARN__}; or, if the module has a way to handle errors, use that. One such warning and it's game over.
Re^2: Checking if a file is present in a ZIP archive
by toolic (Bishop) on Mar 25, 2011 at 17:24 UTC
    Nice guess, but that spews even more messages for me (version 1.26).