#!/usr/bin/perl use strict; use warnings; use diagnostics; use File::Find; use Date::Format; use Date::Parse; sub process { if (-f $_ && /\.html$/) { my $fn = $_; open(F, "<:utf8", $fn) or die("Cannot open ${File::Find::name}: $!"); my $file = ; close F; my ($text, $time); ($text = $1) =~ s/\r\n//mg if ($file =~ m%

(.*?)

%s); $text .= $1 if ($file =~ m%
(.*?)
%s); $time = str2time($1) if ($file =~ /\w+, (\w+ \d\d, \d{4})/s); die "Invalid fileformat: $text $time." unless ($text && $time); $text =~ s/(\r|

|<\/p>|^\s*|[\t ]{2,})//g; $fn =~ s/html$/txt/; open(OUT, ">:encoding(iso-8859-15)", "/home/hynek/old-blog/new/$fn") or die "Cannot open for write: $!."; print OUT $text; close(OUT); utime $time, $time, ("/home/hynek/old-blog/new/$fn"); } } undef $/; find(\&process, ("tmp"));