perldoc -q 'date|time' FAQ -- and -- making same change to *lots* of files, *without* date changed

perldoc -q 'date|time' FAQ -- and -- making same change to *lots* of files, *without* date changed

Post by dkcomb » Wed, 19 Oct 2005 02:43:24


In article <dwH4f.29049$Io.3499@clgrps13>,
John W. Krahn < XXXX@XXXXX.COM > wrote:
...

Well, then whatever date it does change upon a "touch" of the file.


John, how does that help me *edit* the gillion files?,

, all the while, *not* changing any of the dates/times associated
with the files?

I figured that if anyone could come up with a one-liner,
it would be *you*! :-)




FYI: Here's what "perldoc -q 'date|time' >! foo.out" gets me:


Found in /me-FIRST-in-PATH-bin/perl-5.8.6/lib/5.8.6/pod/perlfaq4.pod
How can I compare two dates and find the difference?
If you're storing your dates as epoch seconds then simply subtract one
from the other. If you've got a structured date (distinct year, day,
month, hour, minute, seconds values), then for reasons of accessibility,
simplicity, and efficiency, merely use either timelocal or timegm (from
the Time::Local module in the standard distribution) to reduce
structured dates to epoch seconds. However, if you don't know the
precise format of your dates, then you should probably use either of the
Date::Manip and Date::Calc modules from CPAN before you go hacking up
your own parsing routine to handle arbitrary date formats.

How do I find yesterday's date?
If you only need to find the date (and not the same time), you can use
the Date::Calc module.

use Date::Calc qw(Today Add_Delta_Days);

my @date = Add_Delta_Days( Today(), -1 );

print "@date\n";

Most people try to use the time rather than the calendar to figure out
dates, but that assumes that your days are twenty-four hours each. For
most people, there are two days a year when they aren't: the switch to
and from summer time throws this off. Russ Allbery offers this solution.

sub yesterday {
my $now = defined $_[0] ? $_[0] : time;
my $then = $now - 60 * 60 * 24;
my $ndst = (localtime $now)[8] > 0;
my $tdst = (localtime $then)[8] > 0;
$then - ($tdst - $ndst) * 60 * 60;
}

Should give you "this time yesterday" in seconds since epoch relative to
the first argument or the current time if no argument is given and
suitable for passing to localtime or whatever else you need to do with
it. $ndst is whether we're currently in daylight savings time; $tdst is
whether the point 24 hours ago was in daylight savings time. If $tdst
and $ndst are the same, a boundary wasn't crossed, and the correction
will subtract 0. If $tdst is 1 and $ndst is 0, subtract an hour more
from yesterday's time since we gained an extra hour while going off
daylight savings time. If $tdst is 0 and $ndst is 1, subtract a negative
hour (add an hour) to yesterday's time since we lost an hour.

All of this is because during those days when one switches off or onto
DST, a "day" isn't 24 hours long; it's either 23 or 25.

The explicit settings of $ndst and $tdst are necessary because localtime
only says it returns the system tm struct, and the system tm struct at
least on Solaris doesn't guarantee any particular positive value (like,
say, 1) for isdst, just a positive value. And that value can potentially
be negative, if DST information isn't available (this sub just treats
those cases like
 
 
 

perldoc -q 'date|time' FAQ -- and -- making same change to *lots* of files, *without* date changed

Post by A. Sinan U » Wed, 19 Oct 2005 03:17:20

> FYI: Here's what "perldoc -q 'date|time' >! foo.out" gets me:

What is your point?

Sinan

--
A. Sinan Unur < XXXX@XXXXX.COM >
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.yqcomputer.com/ ~tadmc/clpmisc/clpmisc_guidelines.html

 
 
 

perldoc -q 'date|time' FAQ -- and -- making same change to *lots* of files, *without* date changed

Post by John W. Kr » Wed, 19 Oct 2005 10:25:03


Sorry, I misread the question.


UNTESTED:

perl -MFile::Find -e'find sub {
my ( $atime, $mtime ) = ( stat )[ 8, 9 ];
local ( @ARGV, $^I ) = $_;
s!/home!/myhome!g while <>;
close ARGV;
utime $atime, $mtime, $_;
}, "."'



John
--
use Perl;
program
fulfillment
 
 
 

perldoc -q 'date|time' FAQ -- and -- making same change to *lots* of files, *without* date changed

Post by dkcomb » Wed, 19 Oct 2005 13:26:21

In article < XXXX@XXXXX.COM >,


Good question -- turns out that stuffed a whole lot more
into that post than I intended to. WAY more.

Sorry for having you all look through all that stuff;
shouldn't have been there. :-(


David
 
 
 

perldoc -q 'date|time' FAQ -- and -- making same change to *lots* of files, *without* date changed

Post by dkcomb » Wed, 19 Oct 2005 13:44:41

In article <P9Y4f.33411$S4.32929@edtnps84>,

...
...

Thanks, John!

David