#!/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 = ; chomp(@file); close F; (my $date) = grep m%\w+, \w+ \d\d, \d\d\d\d%, @file; $date =~ m%\w+, (\w+ \d\d, \d\d\d\d)%; my $time = str2time($1); my ($in_text, $in_subject) = undef; my ($text, $subject) = ""; READ: foreach (@file) { if (m%

%) { # Subject $in_subject = 1; } elsif ($in_subject && $_ !~ m%

%) { $subject = $_ if /\w/; } elsif ($in_subject && $_ =~ m%%) { $in_subject = undef; $text = "$subject\n"; } elsif (m%
%) { # Text $in_text = 1; } elsif ($in_text && $_ !~ m%
%) { $text .= $_ . "\n"; } elsif ($in_text && $_ =~ m%%) { last READ; } } $text =~ s/(\r|

|<\/p>|^\s*)//gm; $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"); } } find(\&process, ("tmp"));