On Fri, 2006-11-03 at 08:08 -0600, Tim Wolak wrote:
> Morning all,
>
> I need to compare the current date with that of a file, if the file is
> older than the current date remove it and replace it with a new one from
> new data. Below I have the code set for getting the date but can't come
> up with an easy way to compare it against the file date. Can anyone
> tell me the best way to compare the current date with that of the
> date/time stamp on a file?
>
> Thanks,
> Tim
>
> my $date;
> my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
> $year=$year+1900;
> $mon=$mon+1;
> $date = sprintf("%02d%02d%02d\_%02d\:%02d\:%02d",
> $year,$mon,$mday,$hour,$min,$sec);
Your list slice:
my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
Is completely unnecessary; you can achieve the same with:
my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
Use slices for what they're good for. :-)
Now, why not just check how old the file is in days? You can achieve
this in different ways, the file test operators can help you.
Simple example:
if (int(-M $file) > $x) {
# do something
}
Of course this isn't perfect, you can read more about the file test
operators with "perldoc -f -X". You should also read "perldoc -q
timestamp". I'm sure after reading these specifically the FAQ mentioned
(can be found in perlfaq5), you will be on your way to a good start.
Hope this helps! :-)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>