#!/usr/local/bin/perl
#
# search.pl
# version 961211
# copyright 1996 by bo larsson
# all rights reserved
#
# this CGI program will search a text file for the desired string and generate
# an html table on-the-fly. The text file should have tab-delimited fields and
# return-delimited records.
#
# bugs or feedback to bliss@seagull.net
# for information on how to use, visit http://www.seagull.net/bliss/
# what does the user want to find?
($dump,$search) = split(/=/,$ENV{'QUERY_STRING'});
# let's not make the search case-sensitive, ok?
$ucsearch = uc($search);
$the_file = "./search.txt";
$started_table = "no";
print "Content-type: text/html\n\n";
print "<HTML><BODY>";
print "<TITLE>Search Results</TITLE>";
if ($search ne "")
{
print "<FONT SIZE=+4>Search Results for $search</FONT><HR>";
if (open(THE_FILE, "$the_file"))
{
# begin the table
while (<THE_FILE>)
{
$record = $_;
$_ = uc($_);
if (/$ucsearch/)
{
if ($started_table eq "no")
{
$started_table = "yes";
print "<TABLE BORDER=1 WIDTH=100% BGCOLOR=\"#FFFFFF\">";
}
# begin one table row
print "<TR>";
@fields = split(/\t/,$record);
foreach $field (@fields)
{
# display one data cell for the table row
print "<TD VALIGN=TOP>$field</TD>";
}
# end of one table row
print "</TR>";
}
}
close(THE_FILE);
# end of the table
if ($started_table eq "yes")
{
print "</TABLE>";
}
else
{
print "what you were looking for could not be found.\n";
}
print "<P>";
}
else
{
print "unable to open the file $the_file.\n";
}
}
else
{
print "<FONT SIZE=+4>No query string given</FONT>";
}
print "</BODY></HTML>";