Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: comparing 2 file time date stamps ( Path::Tiny File::stat Time::Piece )

by Anonymous Monk
on Nov 04, 2014 at 03:27 UTC ( [id://1105964]=note: print w/replies, xml ) Need Help??


in reply to comparing 2 file time date stamps

This is bad $year+1900; :) use File::stat through Path::Tiny, use Time::Piece , the convenience is very convenient :) and the error checking exeptions are free
sub cftsain { use Time::Piece qw/ localtime /; use Path::Tiny qw/ path /; my( $source, $destination, $testxt ) = @_; my $sourceStat = path( $source )->stat; my $destStat = eval { path( $destination )->stat }; if( not $destStat ) { path( $source )->copy( $destination ); } else { my $sourceMtime = $sourceStat->mtime; my $destMtime = $destStat->mtime; if( $sourceMtime > $destMtime ) { path( $source )->copy( $destination ); } } if( index( lc( $source ), 'ky2.gif' ) > -1 ) { out_exclusive( $testxt, localtime( $sourceStat->mtime ), localtime( $destStat->mtime ), ); } } ## end sub cftsain
  • Comment on Re: comparing 2 file time date stamps ( Path::Tiny File::stat Time::Piece )
  • Download Code

Replies are listed 'Best First'.
Re^2: comparing 2 file time date stamps ( Path::Tiny File::stat Time::Piece )
by craigt (Acolyte) on Nov 04, 2014 at 04:05 UTC

    Thank you anonymous_monk. Its been a real pleasure to browse through the archives of this place and be able to ask questions of knowledgeable people. I really like this language. I'll work with your suggestion and get back.

      anonymous_monk, I could not get that code to work. The Time-Piece was not available in the repositories PPM checked. I tried with File-Stat and got several PM dependency messages.

      I apologize for not using these facilities as I should sometimes. My lack of experience is showing.

      I tried reversing the file order in the diagnostics. The stat 9 values for both tests were still the values of the file not in the staging directory, in this case now the 2nd file in the diagnostic order. I don't seem to be able to see the file in the staging area.

        I tried
        use File::stat; use Time::localtime; $dd[11] = ctime(stat("$xxfn1")->mtime); $dd[12] = ctime(stat("$xxfn2")->mtime);
        The result was for both files

        Mon Nov 3 11:57:55 2014

        which is the stamp of the file not in the staging directory.

        All methods seem to return the same modification date for both files, even though the file dates are 11/3 and 11/2, respectively.
        The correct files names are printed.
        I'm working on an application on a Windows 7, Apache/2.0.64 (Win32), mod_perl/2.0.3, and Perl/v5.8.3 platform. This version of Perl has been rock solid, so I have not upgraded. If I do need to upgrade Perl, what version should I go to. I've written about 110K lines and the application is up under mod_perl without error. This is a very important function I use in several ways in several places.
        Also, stat seems to get hosed in memory and no longer returns any file information. I have to reboot to get stat to work again.
        I just looked at the date of the file in the staging area in javascript with the same result. stat 9 is not being used in this pass. The file in the staging area keeps showing a Nov 3 date and the external date is Nov 2.

        anonymous_monk, I don't see any way to respond as you requested. I'm sure its me. I only see an option to reply on the entry I've been using and those above on the page.
        I tried
        use File::stat; use Time::localtime; $dd[11] = ctime(stat("$xxfn1")->mtime); $dd[12] = ctime(stat("$xxfn2")->mtime);
        The result for both files was

        Mon Nov 3 11:57:55 2014

        which is the stamp of the file not in the staging directory.

        All methods seem to return the same modification date for both files, even though the file dates are 11/3 and 11/2, respectively.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1105964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found