Skip to content

Instantly share code, notes, and snippets.

@tommybutler
Last active December 29, 2015 09:58
Show Gist options
  • Select an option

  • Save tommybutler/7653376 to your computer and use it in GitHub Desktop.

Select an option

Save tommybutler/7653376 to your computer and use it in GitHub Desktop.
Fix all the bad dates in your CPAN changes file and get it right with the formal specification. This code assumes your dates aren't so mangled that they can't be parsed by Time::ParseDate
cp Changes Changesx ; grep -P '^\d' Changes | perl -MTime::ParseDate -nE 'chomp; $_ =~ s/.*?\s//; $orig = $_; $_ = Time::ParseDate::parsedate( $_ ); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $_ ); $mon+=1; $year+=1900; say sprintf "%4d-%02d-%02d | $orig", $year, $mon, $mday;' | while read parseddate; do echo "$parseddate" | perl -MFile::Util -E '$file = shift @ARGV; $ftl = File::Util->new; $content = $ftl->load_file( $file ); undef $/; $swap = <>; chomp $swap; ( $good, $bad ) = split / \| /, $swap; $content =~ s/\Q$bad\E/$good/smg; $ftl->write_file( $file => $content )' Changesx; echo "$parseddate"; done
# the fixed file is in "Changesx"
@tommybutler

Copy link
Copy Markdown
Author

Yes yes I know the loop should have been in the Perl code. Blech.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment