Mark Atwood (fallenpegasus) wrote,
Mark Atwood
fallenpegasus

Perl script set-date-on-article

A quick-n-dirty bit of Perl I've meant to write for years now.

Give it a list of filenames that contain kindasorta RFC822ish text, and it will "touch" each file so that it's filesystem timestamp matches the "Date:" header.

 #!/usr/bin/perl
use Date::Manip;
foreach $f (@ARGV) {
unless (open(F, $f)) { print STDERR "fail open $f: $!\n"; next; }
read(F, $t, 8192);
close F;
if ($t =~ m/\nDate: ([^\n]*)\n/) {
$d = $1;
$secs = UnixDate($d,"%s");
unless (utime($secs, $secs, $f))
{ print STDERR "fail utime $secs $f\n"; }
} else {
print STDERR "fail parse $f: No Date header\n";
}
}
Tags: date, geek, perl
Subscribe

  • Razors

    I'm getting ads for I think five different "all metal" "get the best shave of your life" "throw away the plastic" razor startups. They all seem to be…

  • Doing what needs to be done

    On May 1st, one of my co-residents found one of the feral rabbits that live in the area cuddled up against a corner of the house. It was seriously…

  • The CTO of Visa, after listening to me present

    Some years ago, I was asked to travel to the corporate meeting center to present at a presentation-fest to the CxO staff of Visa. Yes, the one with…

  • Post a new comment

    Error

    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments