You should check what's actually in @files. Not just for filenames but also whether they exist and (perhaps also) are of the expected size: see the built-in "File Test Operators".

I suspect you probably want to glob "$dir/*.eap". With your posted code, you're only looking for "*.eap" in the current directory. Look for other places where you may be referencing the current directory instead of $dir.

Two other minor points: (1) I wouldn't declare @files globally; (2) foreach and for are synonymous.

Putting all those points together, instead of:

my @files; foreach my $dir (@dirs) { @files = glob "*.eap"; ...

I probably would have written something closer to:

for my $dir (@dirs) { my @files = glob "$dir/*.eap"; ...

For the inner loop, $_ is the default. Adding it the way you have (foreach $_ (@files) { ...) makes me, and quite possibly others, wonder if you perhaps had some other intention, e.g. a lexical 'my $_' (which should be avoided anyway - see below). One of these two forms would be more normal (and won't raise eyebrows):

for (@files) { ...
for my $file (@files) { ...

[Use foreach, instead of for, if you want to. It's really just extra (and unnecessary) typing. As stated earlier, the two are synonymous.]

Using a consistent style of indentation will make your code easier to read and less prone to errors. The choice of coding style is often a very personal one: choose whatever you want. See perlstyle if you want some tips on this.

Finally, and only because I mentioned it passing above, lexical $_ should be avoided. Here's its history:

— Ken


In reply to Re^3: Create zip files for each sub-directory under a main directory by kcott
in thread Create zip files for each sub-directory under a main directory by mrd1019

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.