Here's how I'd do it (untested):
#!/usr/bin/perl -w use strict; my @files = (); my $dir = "/home/dhaffner/src/codemonkey/test"; my $lastUpdate = 0; LOOP: { opendir(DIR, $dir) or die "Died: $!"; @files = grep { -f "$dir/$_" && (stat "$dir/$_")[9] > $lastUpdate +} readdir(DIR); closedir(DIR); GoProcess("$dir/$_") foreach @files; $lastUpdate = time; sleep 30; redo LOOP; }
...but I'm not sure if time() will return the new time, or keep returning the time when the script was first executed. I'll try to find out, and post more in a little while.

Update: Hmm, well I can't find any info one way or the other. It seems like the camel says that time() returns the time when the script started executing, but I can't remember now, and I haven't got the camel here. Anybody?

Update 2: The wise arturo says that time() will return the current time, not just the time the script started... so it should work fine.

Hot Pastrami

In reply to Re: Help periodically scanning directories to process new files by Hot Pastrami
in thread Help periodically scanning directories to process new files by frogleg

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.