in reply to Perl process to constantly detect the time change of a file?
You could cut out a lot of code by using stat - specifically "mtime", which is the "last modify time in seconds since the epoch". I would suggest putting a small sleep time in the loop as well, just so you're not constantly hitting your machine - unless it's absolutely crucial that you know the second when this file has changed.
my $file = "somefile.txt"; # Establish a base "last accessed time" my $lastaccessed = (stat($file))[9]; while(1) { if ((stat($file))[9] == $lastaccessed) { # The file is the same } else { # File is different } sleep 5; }
Check the docs for stat - it provides a lot of useful info about files.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Perl process to constantly detect the time change of a file?
by graff (Chancellor) on May 03, 2002 at 21:33 UTC |