in reply to perl fool - inserting text into html doc
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: perl fool - inserting text into html doc
by Anonymous Monk on Apr 02, 2002 at 15:08 UTC | |
by tachyon (Chancellor) on Apr 02, 2002 at 23:08 UTC | |
by archen (Pilgrim) on Apr 02, 2002 at 16:56 UTC | |
by Fletch (Bishop) on Apr 02, 2002 at 20:00 UTC | |
by archen (Pilgrim) on Apr 03, 2002 at 01:00 UTC |