curtisb has asked for the wisdom of the Perl Monks concerning the following question:
Everyone,
Ok, I have been working on this for a few days now and I am confused. I'm able to get the epoch time from stat and determine which file is newer. Yet, when I use localtime to try and find the DMYHMS format to the same problem, I get nothing but errors. Can someone please help!
To give you some background. I have a remote server on the otherside of the world, I need to check the date on a file on the remote server, if the date is older then the one on my local server, copy the new file from the local server to the remote server.
I want to do all this by comparing either the date modified or the date changed that is time stamped onto the file.
Now here is the code for the stat. Which gets the epoch time and divides by 60,60,60,24,7 to get the time in epoch seconds since 1970.
#!/usr/bin/perl -w use File::Copy; $filename1 = "c:/progra~1/imms"; #file on the client (win +95/98). $filename2 = "//bmc_1/imms_stock/imms_exe/imms.exe"; #file on serve +r. @file1 = stat($filename1); #print "$file1[10]\n"; @file2 = stat($filename2); #print "$file2[10]\n"; $days1 = ((((($file1[10] /60) /60) /60) /24) /7); #print "$days1\n +"; $days2 = ((((($file2[10] /60) /60) /60) /24) /7); #print "$days2\n +"; if ($days1 < $days2) { print "$filename1 is old\n"; copy ($filename2, $filename1) or die "copy failed: $!\n"; print "$filename2 updated!\n"; }else{ print "$filename2 is up to date!\n"; print "No files copied!\n"; }
What I need is to break the epoch seconds down by using the localtime function. I have been looking at both the non-module way and the module way of doing this. I feel that I need to know the non-module way first. Especially for this project.
Here is what I have so far.
$filename1 = "u:/curtisbl/documents/conditional.sql.txt"; ($seconds, $minutes, $hours, $day_of_month, $month, $year, $wday, $yda +y, $isdst) = localtime($filename1); printf ("Time: %02d-%02d-%04d\n", $month+1, $day, $year+1900);
Could someone help please?
Curtisb
"Confused Dated Person"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: stat and localtime
by davorg (Chancellor) on Dec 20, 2001 at 18:17 UTC | |
|
Re: stat and localtime
by grinder (Bishop) on Dec 20, 2001 at 19:33 UTC | |
|
Re: stat and localtime
by Juerd (Abbot) on Dec 20, 2001 at 18:18 UTC | |
by Beatnik (Parson) on Dec 20, 2001 at 18:39 UTC | |
|
Re: stat and localtime
by lordsuess (Scribe) on Dec 20, 2001 at 23:19 UTC | |
|
Re: stat and localtime
by curtisb (Monk) on Dec 20, 2001 at 19:57 UTC |