Perl Newby has asked for the wisdom of the Perl Monks concerning the following question:

I am currently running a Perl script that converts a text file to an HTML format that is posted to a web site. Right now I am trying to set up a trigger on my server to run this script. I know before the file arrives what it's name will be, however, there is going to be around 180 files. Instead of writing a trigger for each file, which is what I am doing now. I wanted to know if there was a way I could right a Perl script that actually checked the time stamp on the file and would then set off the trigger, running the latest version of the mlb_boxscore file. Below is an example of the files I receive. The files are always in this format, nothing changes except the numbers after the $ sign.
mlb_boxscore$210508 mlb_boxscore$210907 mlb_boxscore$214503 mlb_boxscore$213306 mlb_boxscore$220345 mlb_boxscore$219201
Any suggestions?

Replies are listed 'Best First'.
Re: Running a Trigger
by Masem (Monsignor) on May 15, 2001 at 01:07 UTC
    Do you have access to cron? It might be better to have a script run every 5 minutes (or less, or more, depending on the frequency these files come in), in which you can check the time stamp using the stat() function, compare it against the last time it was run (saved in a file somewhere), and decide what actions to take at that time. While you could have a perl script that runs indefinitely, continually scanning the blessed dir until something new comes in, this is going to eat your CPU like there's no tomorrow.
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      Well, not if you sleep() for, say, 1 minute between scans.

        Before you start looping with sleep() indefinitely, you might want to take a look at Have children maintain themselves or main script maintain children. Some good points are made in that thread about the memory use, process longevity, and garbage collection issues.

        Just thought it was worth mentioning. And it was interesting reading!

        D a d d i o