We are building the HTML pages from a template utilizing the HTML::Template module from CPAN. Besides the plain HTML the template has additional TMPL_* tags that will be filled by the values by HTML::Template.
Example 15-14. examples/applications/html.tmpl
<html> <head> </head> <body> <TMPL_IF echo> You typed <TMPL_VAR echo> </TMPL_IF> <form> <input name="text"> <input type=submit" value="Echo"> </form> </body> </html>
This is a simple Perl script that should be installed to a CGIExec enabled directory of Apache. When the user hits this page the first time it displays a white page with only entry-box and a submit button on it. the user can fill the box,
Example 15-15. examples/applications/html.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use HTML::Template;
my $template = HTML::Template->new(filename => "examples/html.tmpl");
my $q = CGI->new;
print $q->header;
if ($q->param("text")) {
my $text = $q->param("text");
$template->param(echo => $text);
}
print $template->output
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Fetch web page | Up | Parse XML file |