Mike Gossland’s Perl Tutorial Course for Windows

Chapter 7. CGI In Use

CGI In Use
Site search
Presenting data from a database
Handling cookies
Uploading files to the server
Requesting info from other servers

Performing a Site Search

Performing a site search is pretty straightforward because finding which pages hold a certain term is easy. We use File::Find to look through all the files, and we just do a match on the searched term to see if it's in the page.

The example below is complicated a little because it's set up to run on a Windows or a Linux server, and some details are different between the two.

There are some new constructs for you to encounter, such as using environment variables and the "||=" operator, which is used to set a variable to a value only if it does not already have a value.

First you need a form to ask for the search term. There's one in this form. The action of the form is "search.pl" and the field is called "search_term"

Here is the script that does the work

Next Page

Search this site or the web:

just this site the whole web

Questions? Feedback?

Email me your comments!