Listing 4. template.pl

#!/usr/bin/perl -w
# template.pl, a CGI program that expects to 
# receive the name of the template file in the 
# query string (aka "keywords")
use strict;
use diagnostics;
use CGI;
use Text::Template;
# Create an instance of CGI
my $query = new CGI;
# Send an appropriate MIME header
print $query->header("text/html");
# Get the keywords
my $filename = $query->param("keywords");
# Remove any attempts to move up a directory
$filename =~ s|../||g;
# Get the name of the template
my $file = "/usr/local/apache/share/templates/$filename";
# Create an instance of template
my $template = new Text::Template(-type => "FILE", -source => $file);
# Perform the evaluation, and send the results
# to the user's browser
print $template->fill_in;