Wrong operator. The times are numbers, so you should use a
numeric comparison operator:
if ($modfile == $orgtime)
Here is my code again with the use of strict and warnings. I have
tried to use the statement:
if ($modfile == $orgtime)
But I get an error message saying that the argument isn't numerical
data and that I need to use eq. And I think that is because I changed
the format of $modfile and $orgtime to "localtime" so that it read in
as a string date and time reference.
#!/usr/bin/perl -w
use strict;
use File::stat;
#need to set $filename equal to the file that is being monitored
my $filename = "C:/temp/test.txt";
#converts the epoch time into a readable format.
my $orgtime = ($^T);
open FILEHANDLE, $filename or die "Cannot open $filename,
err=\"$!\"\n";
while (<FILEHANDLE>)
{
#Sets the epoch time inot a readalbe format
#Checks to see what the last modification time since the epoch
is
(my $mtime,) = stat($filename);
$mtime = localtime;
#Compares the mtime vs against the orginal epoch
if ($mtime == $orgtime)
{
print ("$filename has not changed \n");
}
else
{
print ("Attention! \n");
print ("$filename has been modified on $mtime \n");
}
# set the oringal epoch time to = the new modified
time.
# This doesn't work though and I can't figure out why.
$orgtime = $mtime;
}
print ("Done. \n");
close (FILEHANDLE)
Right now it works and tells me that the file has been modified. But I
can't figure out how to reset the orginal epoch time ($orgtime) to =
the time after the "Attention file has been modified message" has been
sent so that when it loops back through it can tell what is just old
modifications that have already been picked up on and what are new
changes to the file. Does that make sense?
Thanks so much for looking at this!