perlquestion
craigt
I'm comparing 2 file date time stamps to decide if 1st file is newer than the file in the staging areas. The copy works correctly if I comment out the stat 9 test.
<code>
sub cftsain {
my ($xxfn1, $xxfn2) = @_;
my @dd = ();
$dd[7] = 0;
$dd[8] = 0;
if ( defined (( stat "$xxfn1" )[9]) ) {
$dd[7] = (( stat "$xxfn1" )[9]);
}
if ( defined (( stat "$xxfn2" )[9]) ) {
$dd[8] = (( stat "$xxfn2" )[9]);
}
# Copy the image file if not there or changed.
$dd[0] = 0;
if (!-e $xxfn2) {
copy "$xxfn1", "$xxfn2";
} else {
# Database image is newer than staging space image.
if ( (( stat "$xxfn1" )[9]) > (( stat "$xxfn2" )[9]) ) {
#if ( -M "$xxfn1" > -M "$xxfn2" ) {
copy "$xxfn1", "$xxfn2";
$dd[0] = 1;
}
}
$dd[1] = $xxfn1;
$dd[2] = $xxfn2;
$dd[3] = (( stat "$xxfn1" )[9]);
$dd[4] = (( stat "$xxfn2" )[9]);
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($dd[3]);
$year = $year+1900;
$mon = $mon+1;
$dd[5] = $sec.' '.$min.' '.$hour.' '.$mday.' '.$mon.' '.$year.' '.$wday.' '.$yday;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($dd[4]);
$year = $year+1900;
$mon = $mon+1;
$dd[6] = $sec.' '.$min.' '.$hour.' '.$mday.' '.$mon.' '.$year.' '.$wday.' '.$yday;
$dd[9] = -M $xxfn1;
$dd[10] = -M $xxfn2;
if ( index(lc($xxfn1),'ky2.gif') > -1 ) {
out_exclusive('c:/usr/www/test.txt', @dd);
}
}</code>
Results are<br><br>
0<br>
C:/Steep/USA Data/State/KY/ky2.GIF<br>
C:/usr/www/steepusa/stage/KY/KY2.GIF<br>
1415033875<br>
1415033875<br>
55 57 11 3 11 2014 1 306<br>
55 57 11 3 11 2014 1 306<br>
1415033875<br>
1415033875<br>
-0.035775462962963<br>
-0.035775462962963<br><br>
The 2nd file has the same stat 9 as the first. The 2nd should be 11/2.<br><br>
I did try the -M and the test failed with the 2 large negative numbers (???) that are the same. I also tried the defined tests at the top of the subroutine and captured the stat 9 values if defined. They were defined and are the same. Also, I do use strict and -w flag.
<p><small><b>Original code restored below by [GrandFather]</b></small></p>
<code>
sub cftsain {
my ($xxfn1, $xxfn2) = @_;
my @dd = ();
# Copy the image file if not there or changed.
$dd[0] = 0;
if (!-e $xxfn2) {
copy "$xxfn1", "$xxfn2";
} else {
# Database image newer than staging space image.
if ( ( stat "$xxfn1" )[9] > ( stat "$xxfn2" )[9] ) {
copy "$xxfn1", "$xxfn2";
$dd[0] = 1;
}
}
$dd[1] = $xxfn1;
$dd[2] = $xxfn2;
$dd[3] = ( stat "$xxfn1" )[9];
$dd[4] = ( stat "$xxfn2" )[9];
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($dd[3]);
$year = $year+1900;
$mon = $mon+1;
$dd[5] = $sec.' '.$min.' '.$hour.' '.$mday.' '.$mon.' '.$year.' '.$wday.' '.$yday;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($dd[4]);
$year = $year+1900;
$mon = $mon+1;
$dd[6] = $sec.' '.$min.' '.$hour.' '.$mday.' '.$mon.' '.$year.' '.$wday.' '.$yday;
if ( index(lc($xxfn1),'ky2.gif') > -1 ) {
out_exclusive('c:/usr/www/test.txt', @dd);
}
}
</code>