Here is the code for what you are trying to do. I assume that you place a token like <TMPL_VAR NAME=TEXT> in the HTML template file:

#!/usr/bin/perl -w use strict; my $template = get_file ( 'c:/some/template.htm' ); my $textfile = get_file ( 'c:/some/textfile.txt' ); $template =~ s/<TMPL_VAR NAME=TEXT>/$textfile/ or die "No token!"; print "Content-Type: text/html\n\n"; print $template; sub get_file { my $file = shift; open FILE, $file or die "Can't open $file $!\n"; local $/; my $content = <FILE>; return $content; }

Now as it happens <TMPL_VAR NAME=TEXT> is what you use with HTML::Template. The corresponding code would be:

use HTML::Template; # open the html template my $template = HTML::Template->new(filename => 'some/template.html'); # get the text ( get_file() code above) my $sometext = get_file( '/some/textfile.txt' ); # fill in some parameters $template->param( TEXT => $sometext ); # send the obligatory Content-Type print "Content-Type: text/html\n\n"; # print the template print $template->output;

If you *really* have a problem with module installation you can install them locally or as a last resort you can ditch the use HTML::Template; line in the code above and just paste the entire module at the end of your code.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: perl fool - inserting text into html doc by tachyon
in thread perl fool - inserting text into html doc by cameltrader

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved 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.