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

Hello, I was wondering if someone could help me. I would like to pause the execution of a perl script until a particular file is created (say file.log). Is this possible? Thanks in advance.

Replies are listed 'Best First'.
Re: Pause Perl Script Execution
by oxone (Friar) on Sep 08, 2007 at 15:25 UTC
    Assuming the file in question will be created by something external to your Perl script and you just want to wait:
    sleep 1 while !-e 'myfile.txt';
    Note that !-e means "file doesn't exist". This will keep looping and checking every 1 second forever, and move on only if the relevant file appears.
Re: Pause Perl Script Execution
by moritz (Cardinal) on Sep 08, 2007 at 15:30 UTC
    It is considered bad style to ask in the CB and in SoPW as well without mentioning that, especially if you got good answers in the CB.

    Regarding your question: depending on your OS there might be a more elaborate solution, like Win32::ChangeNotify (pointed out by tye++), or dnotify on Linux (ambrus++), I don't know if there is a perl frontend for that.

    (Update: clarified first sentence)

      inotify currently finds two module distributions that claim to support such. One complains about the other but has two reviews complaining about it.

      - tye        

        First sorry to post both in the CB and here, didn't realise it was the wrong approach. Second, I lost internet this avo so couldn't reply immediately. About pausing the perl script, I'm on a linux OS...not sure what this changes for the solution you've posted - many thanks for all your help so far guys.