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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |