in reply to Converting a date to a string and back

If you need the timediff's only then why not create a separate marker file and with -M you can get the age of the file in seconds? note, that "age" is actually the age in seconds from the moment the perl script started, so if you use a daemon, it will not work, however, if your script starts regularly or on-demand, this works:

#!/usr/bin/perl use strict; use warnings; my $TESTFILE='/tmp/x'; unless (-f $TESTFILE){ open(TF, '>',$TESTFILE) or die $!; close(TF); } my $AGE_seconds = -r $TESTFILE ? int( (-M _) *60*60*24) : -1; print "the file $TESTFILE is $AGE_seconds seconds old.\n";

As for the timelocal(), roll your own, with a simple regular expression you are all set. Just be careful to not match a date in the other fields.

Replies are listed 'Best First'.
Re^2: Converting a date to a string and back
by choroba (Cardinal) on Jul 14, 2016 at 23:12 UTC
    > if you use a daemon, it will not work,

    Fortunately, there's $^T to compensate:

    $ touch 1 $ sleep 2 $ perl -wE ' say 24 * 60 * 60 * -M "1"; sleep 2; say time - $^T + 24 * 60 * 60 * -M "1"; ' 2 4

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Thank you choroba, very insightful (you got my vote)... adding (time - $^T) to my snippets files...