use File::CounterFile; my $counter = File::CounterFile->new("/path/to/sentinel.txt", "0000"); chdir "/path/to/where/the/files/are" or die "chdir: $!"; ## see if a new file has arrived while (-e (my $file = "elmo$counter.txt")) { process_file($file); $counter = "0000" if ++$counter == "10000"; }
You might need to initialize sentinel.txt to sync it up to the first file. Just put "1234" (no newline) into the file, where you expect elmo1234.txt to be the next rsync'ed file.

update: (to add some explanation...)

The File::Counterfile module creates a persistent file. The object returned from the module is overloaded so that it can be incremented and interpolated, but every change to the object gets reflected as a change to the original file. It uses Perl's "magical autoincrement" to generate items here from 0000 to 9999. Of course, when that wraps, I need to force it back to 0000. I'm also presuming this program gets invoked every 15 minutes or whatever, and that process_file unlinks the file as it does the job.

And now the explanation is longer than the program, so I'll stop. {grin}

-- Randal L. Schwartz, Perl hacker


In reply to Re: processing logic help by merlyn
in thread processing logic help by agoth

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.