in reply to Need help with a Simple File, transferring a plain text document to a plain HTML document

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

  • Comment on Re: Need help with a Simple File, transferring a plain text document to a plain HTML document
  • Select or Download Code