#!/usr/local/bin/perl -w # this script searches the given web directory for # pages containing the given search term. Need to run # cache.pl first to create the cache file. use lib 'your_file_path'; use strict; use CGI qw(:standard); use HTML::Template; my $cache = '/u/www/virtual/w01-0785/sitesearch.dat'; # path to cache file. my $param = 'search'; # name field from input tag # in calling web page. # get the web site data from the cache: open RETRIEVE, $cache or die "could not open $cache $!"; my $data = do { local $/; }; my @Retrieves = @{ my $VAR1; eval $data }; # search the data and pull out the relevant filenames and page titles: my $SearchTerm = param($param); my @Results; my $text; for (@Retrieves) { if ($_->{text} =~ /$SearchTerm/i) { push @Results, {filename => $_->{filename}, title => $_->{title}}; } } # print the search results: my $results_tmpl = HTML::Template->new(filename => 'siteresults.tmpl'); $results_tmpl->param( search_term => $SearchTerm, results => [@Results], ); print header; print $results_tmpl->output();