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.
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($d
+d[3]);
$year = $year+1900;
$mon = $mon+1;
$dd[5] = $sec.' '.$min.' '.$hour.' '.$mday.' '.$mon.' '.$year.' '.$wda
+y.' '.$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.' '.$wda
+y.' '.$yday;
$dd[9] = -M $xxfn1;
$dd[10] = -M $xxfn2;
if ( index(lc($xxfn1),'ky2.gif') > -1 ) {
out_exclusive('c:/usr/www/test.txt', @dd);
}
}
Results are
0
C:/Steep/USA Data/State/KY/ky2.GIF
C:/usr/www/steepusa/stage/KY/KY2.GIF
1415033875
1415033875
55 57 11 3 11 2014 1 306
55 57 11 3 11 2014 1 306
1415033875
1415033875
-0.035775462962963
-0.035775462962963
The 2nd file has the same stat 9 as the first. The 2nd should be 11/2.
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.
Original code restored below by GrandFather
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($d
+d[3]);
$year = $year+1900;
$mon = $mon+1;
$dd[5] = $sec.' '.$min.' '.$hour.' '.$mday.' '.$mon.' '.$year.' '.$wda
+y.' '.$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.' '.$wda
+y.' '.$yday;
if ( index(lc($xxfn1),'ky2.gif') > -1 ) {
out_exclusive('c:/usr/www/test.txt', @dd);
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link or
or How to display code and escape characters
are good places to start.