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

Hello Monks

I got a perl script which looks for file in a directory for specified time and in between if file comes then the program
quits saying file has come and if not comes out with a message after the specified time file hasn't come...this script was written in 1996 in perl using alarm function...but the latest versions of perl Active State 5.8 doesn't seem to implement alarm function...what will be the approach to this problem because our systems are upgraded with latest perl version and this script no longer works..

Appreciate any help in this regard

alarm($endsecs); local $SIG{'ALRM'}="TimeOut"; print STDOUT "*** FileWatch is waiting...\n";
Thanks & Regards
Sridhar

2006-10-28 Retitled by GrandFather, as per Monastery guidelines
Original title: 'FileWatch'

Replies are listed 'Best First'.
Re: Using the alarm function in ActiveState Perl 5.8 for FileWatch
by philcrow (Priest) on Oct 27, 2006 at 18:09 UTC
    Perhaps you could use a foreach loop with a sleep:
    foreach my $i ( 1..10 ) { # look for file, if it's there quit happily sleep 6; # wait 6 seconds and try again } # perhaps make one final check # quit unhappily
    Phil
Re: Using the alarm function in ActiveState Perl 5.8 for FileWatch
by runrig (Abbot) on Oct 27, 2006 at 18:20 UTC
    Win32::ChangeNotify doesn't seem to have a timeout option, but you could accomplish it with the POE wrapper, or the ruby version of Win32::ChangeNotify does look like it has a timeout argument to the wait function.

    Update: I am corrected. Win32::ChangeNotify::wait() does have a timeout argument. I just wish you didn't have to look up the docs recursively :-)

Re: Using the alarm function in ActiveState Perl 5.8 for FileWatch
by Anonymous Monk on Oct 29, 2006 at 05:10 UTC
    $ENV{PERL_SIGNALS} = 'unsafe';