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.
In reply to Re: Perl process to constantly detect the time change of a file?
by Rich36
in thread Perl process to constantly detect the time change of a file?
by blackcode6
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |