in reply to Re: Hints for getting this perly...
in thread Hints for getting this perly...
Any comments? Thanks for the support so far!#!/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 = <F>; close F; my ($text, $time); ($text = $1) =~ s/\r\n//mg if ($file =~ m%<h3 class="post-titl +e">(.*?)</h3>%s); $text .= $1 if ($file =~ m%<div class="post-body">(.*?)</div>% +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>|<\/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"));
|
|---|