if(scalar(@Files) > 1)
I agree that this code seems strange, and I will attempt to explain my reason with a concrete example.

The OP is looking at files in a single directory, $DirPath = "/tmp//testing"; (those double slashes look a little messy, but let's ignore that). Let's assume that the directory contains exactly 3 items the first time through the while loop: the 2 special dot directories (. and ..) and 1 file named foo.txt. The readdir will return a list of 3 items, and the grep will filter out the 2 directories. Thus, the @Files array will contain 1 item (the file foo.txt). Since scalar(@Files) resolves to 1, which is not greater than 1, the code enters the else clause and sleep's for 10 seconds.

Therefore, there is no -M check on the foo.txt file during the first pass through the while loop because it is the only file in the directory. I doubt that is what the OP really wants.

In fact, there will be no -M checks until there are at least 2 files in the directory, no matter how many 10 second intervals (and times throught the loop) elapse.

Perhaps the OP has never encountered this corner case because there are always at least 2 files in the directory. Or maybe the OP just does not care about this case. But, it does seem strange to me. To avoid this corner case, if(scalar(@Files) > 0) could be used (or, more simply if(@Files)).

Another reason the OP may never notice this case is if the directory contains at least 1 subdirectory. For example, if $DirPath contains a directory 'bar' in addition to file foo.txt, then the @Files array will contain 2 items (bar and foo.txt) after the grep/readdir. In this case, if(scalar(@Files) > 1) would be true, and the -M check would be preformed on the foo.txt file, but just as a happy accident. Again, I doubt that is what the OP really wants.

If it were my code, I would filter out all directories with grep, not just the 2 special dot directories:

my @Files = grep { -f "$DirPath/$_" } readdir DIR;

In reply to Re^2: Resseting perl -M file mod after xx minutes by toolic
in thread Resseting perl -M file mod after xx minutes by learningperl01

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.