in reply to Thread to read a file every second

It is not clear why you need threads to do this, more detail might be in order. perlthrtut would be a good point to start for info on threads.

my $file = '/path/to/some/file'; while(1) { if ( -e $file ) { # read file # do stuff # unlink $file; # otherwise we will keep finding it } sleep 1; }

If you want to use simple code like this you will want to daemonize it. There is a example of daemonizing on my scratchpad

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Thread to read a file every second
by TedPride (Priest) on Oct 06, 2004 at 08:24 UTC
    tachyon: Isn't that an endless loop? Also, he probably wants threading so his program doesn't stick endlessly or wait for x number of seconds for each file that isn't there. Better to wait x seconds rather than xn seconds.

    EDIT TO PREVIOUS: I should have put in an end check parameter:

    sub check_file { my ($fpath, $arrp) = @_; my $max = 15; my $handle; while (!-e $fpath || !open($handle, $fpath)) { return if (!$max--); sleep(1); } $$arrp = join('', <$handle>); close($handle); }