in reply to Re: file modified
in thread file modified

Yeah it does not work properly. Basically if a file has not been modified for more than an hour, I go and check the contents of the file (comparison etc.), else I wait till the last modified time becomes more than 1 hr

What is really happening is that my code goes into the while loop and does not come out...even after an hour. What do you advice? Thanks.

Replies are listed 'Best First'.
•Re^3: file modified
by merlyn (Sage) on Jan 07, 2005 at 17:00 UTC
    What is really happening is that my code goes into the while loop and does not come out...even after an hour. What do you advice? Thanks.
    (Smacking hand on forehead...)

    It would have helped for you to say that! OK, I see what's happening now. -M is not going to change in that loop for a file that's being "left alone", because the value is measured relative to the start of the program (as captured in $^T)!

    Maybe what you want is more like this:

    { die unless my @stat = stat $the_file; my $seconds_until_one_hour_old = 3600 - (time - $stat[9]); last if $seconds_until_one_hour_old <= 0; # already old enough sleep $seconds_until_one_hour_old; # not yet redo; # and test again }

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.