in reply to Hints for getting this perly...

Thanks for the feedback so for, a first update based on the suggestions would be:
#!/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 ($in_text, $in_subject) = undef; my ($text, $subject, $time); while (<F>) { chomp; if ($_ =~ /\w+, (\w+ \d\d, \d{4})/) { $time = str2time($1); } elsif (/<h3 class="post-title">/) { # Subject $in_subject = 1; } elsif ($in_subject && $_ !~ m%</h3>%) { $subject = $_ if /\w/; } elsif ($in_subject && $_ =~ m%</h3>%) { $in_subject = undef; $text = "$subject\n"; } elsif (/<div class="post-body">/) { # Text $in_text = 1; } elsif ($in_text && $_ !~ m%</div>%) { $text .= $_ . "\n"; } elsif ($in_text && $_ =~ m%</div>%) { last; } } die "Invalid fileformat: $text $time." unless ($text && $time) +; $text =~ s/(\r|<p>|<\/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"));
Now I'm going to read it flatly and try to utilitize the ".."-operator...let's see how it further shortens the script (comments on this code are still welcome though).

Replies are listed 'Best First'.
Re^2: Hints for getting this perly...
by hynek (Novice) on May 11, 2005 at 13:26 UTC
    ".." proved to be kinda pointless...but I really like my new version: :)
    #!/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"));
    Any comments? Thanks for the support so far!