I need to write a script that does the following:

1) Examines a bunch of files (specified on the command line or whatever).

2) If some of them are ZIP archives, check if they contain a file with a particular name.

3) If they do, print the name of the ZIP archive.

I have written the script and it works, but I have a couple of questions:

1) I use the Archive::ZIP package. Problem is, if I try to use it on a file that isn't a ZIP archive, it barfs a bunch of errors. I would have expected it to fail gracefully and return some kind of error code, if the file isn't a properly formatted ZIP archive - but I was unable to make it behave like this. I have circumvented the issue by checking if the file begins with the ZIP archive signature ("PK\003\004") before opening it with Archive::ZIP->new() but I was wondering if there was a more elegant way.

2) Given that I don't need to extract anything from the archive (only check if a file exists inside), perhaps using the whole Archive::ZIP package is an overkill? Is there a more efficient way?


In reply to Checking if a file is present in a ZIP archive by bontchev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.