Dearest Monks,

I would like to search through all the files in a directory, and see if at least one of them is new (m-time, say). When I find one, i need to stop the depth-search.

Your thoughts will be highly appreciated!

use strict; use warnings; use File::Find; my $base = '/my/working/directory'; finddepth(\&no_old_dir_please, $base); sub no_old_dir_please { return if ((-M $_) <= 30); # how to quit finddepth on this con +dition? }

I know I could set a flag once i hit a new file and then just return in the sub if that flag is true. But the reason i want to stop processing is that there could 100 /1000 more files but the moment I find a new file there is no point in checking other files.

To summarize in the problem in a line: Flag the given directory as "old" if there are no new files (based on some m-time condn).

Thanks!

-SK

Update: I don't want to quit the program as I could be checking a bunch of directories like this in a loop.


In reply to How to conditionally terminate finddepth? by sk

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.