Jeff Pang wrote:
2007/10/5, [EMAIL PROTECTED]
<[EMAIL PROTECTED]>:
I would like to compare two files by comparing the files dates.
If one file shows
ls -la May 12 2003 filename
and the other name shows the same date they are OK for me (I'm not
interested in the time part only the date of the file)
But if the dates are not the same I would like to copy one of the
files.
How do I do this in Perl?
if ( int(-M "file1.txt") != int(-M "file2.txt") ) {
# copy the file
}
That might be true also when the dates are the same. I would use stat(),
localtime() and timelocal() instead.
use Time::Local;
my $date1 = timelocal 0,0,0,(localtime( (stat 'file1.txt')[9] ))[3..5];
my $date2 = timelocal 0,0,0,(localtime( (stat 'file2.txt')[9] ))[3..5];
if ( $date1 != $date2 ) {
# copy the file
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/