You should consider using something like HTML::Template to generate the HTML frame and then do a simple substitution in your text to get the desired formatting. Your template will look something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title> <TMPL_VAR ESCAPE="HTML" NAME="title"> </title> <style> .hit { font-color: red; font-weight: bolder; } </style> </head> <body> <TMPL_VAR ESCAPE="HTML" NAME="my_text"> </body> </html>

And your Perl code will resemble this:

#!/usr/local/bin/perl # Usage: perl "thisfile.pl inputfile.txt" use warnings; use strict; use HTML::Template; my $title = "Page Title"; # or a variable representing a # command-line argument, or # something extracted from your # input file. my $text; { local $/ = undef; $text = <>; } $text =~ s/\b(myword)\b/<span class="hit">$1</span> /g; my $template = HTML::Template->new(filename => 'my_template.tmpl'); $template->param(date => "$title"); $template->param(date => "$text"); print $template->output;

Caveat: I haven't tested this code.

--
Allolex

Perl and Linguistics
http://world.std.com/~swmcd/steven/perl/linguistics.html
http://www.linuxjournal.com/article.php?sid=3394
http://www.wall.org/~larry/keynote/keynote.html




  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.