Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Wednesday January 07, 2004
12:11 PM

New journal reader template

[ #16698 ]

I updated my use.perl journal reader output template. It now nicely handles ECODE sections, and makes a text listing of the URLs at the end of the post.

I still have a few problems with it, but it mostly works and I will fix those in the next go around.

Notice, in the code, that I had to change the literal close ECODE tag to E-CODE to get the template to display correctly for this post.

{
use HTML::Entities;
use Text::Autoformat;
 
$entry{body} =~ s=</?(p|blockquote)/?>=\n\n=gi;
$entry{body} =~ s=</?tt>==gi;
$entry{body} =~ s|</?i>|__|gi;
$entry{body} =~ s|</?b>|*|gi;
 
$last_entry = "0";
 
while( $entry{body} =~ s|\s*<ecode>(.*?)\s*</e-code>\s*|\n\n**$last_entry**\n\n|is )
    {
    my $ecode = $1;
    $ecode =~ s/^/\t/gm;
 
    push @ecodes, $ecode;
    $last_entry++;
    }
 
$last_entry = 0;
 
while( $entry{body} =~ s|<a.*?href=(['"])(.*?)\1.*?>(.*?)</a>|$3\[$last_entry]|is )
    {
    push @urls, $2;
    $last_entry++;
    }
 
decode_entities( $entry{body} );
 
my $text = autoformat( $entry{body}, { right => 73, all => 1 } );
 
$text =~ s/\*\*(\d+)\*\*/$ecodes[$1]/g;
 
$text =~ s|\n{3,}|\n\n|gi;
$text =~ s=^\n+|\n+$==gi;
 
$text .= join "\n\t", undef, undef, map { "[$_] $urls[$_]" } 0 .. $#urls;
 
"
================================================================== ====
$entry{nickname}: $entry{subject}
$entry{date}, $entry{id}
-------------------------------------------------------------------- --
 
$text
";
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.