Page is a not externally linkable
- Code, Content, and Presentation
-- Perl Server Side CGI Scripting
---- CGI displays Perl Script


lappert2001 - 1:09 am on Feb 29, 2012 (gmt 0)


FYI, here's the text of srch.cgi. It's old but it worked for many years.

#!/usr/bin/perl
# srch.pl
$|=1;
require("cgi-lib.pl");
print &PrintHeader;
&ReadParse;
$delm="\t";
#########enter file names here
@file=("ny.txt","bronx.txt","queens.txt","brooklyn.txt","richmond.txt","west.txt","nassau.txt","rockland.txt");
#########

$whichfile=$file[$in{'sel'}];
print "<HTML><HEAD>\n";
print "<TITLE>Page Title</TITLE></head>";
print '<body BGCOLOR="ffffe7" text="000000">';

########in input is not a null string then search#####
if($in{'query'}){

print '<h1><b> Page text</b></h1>';
print '<i> More Page text</i><br>';
print '<i> Even More Page text.</i><br>';
print ' <b>Page text</b> <a href="misc.html">Misc information</a>';
print '<hr>';

###############
#open online database
##############
open(FILE,"$whichfile");

$found=0;
$count=$tally;
#initialize variable to tally
#loop to look for model by name
#print $in{'query'};

while (<FILE>){
$ct++;
#@field=split($delm,$_);
#if(($_=~/^$in{'query'}/i)&&($in{'query'})){
#####test query#####
if(($_=~/$in{'query'}/i)&&($in{'query'})){

$_=~s/\#/ <b> Page text<\/b> /i;
$_=~s/\*/ <b> More page text<\/b> /i;
print $_,"<br>";
$found++
}
#####################end test query###
}

#print " $ct";

if($found <1){print'<h1>Nothing Matched</H1>'}else{print "$found Matches found<br>"};

close FILE;
}


######################GET TIME############################
($sec,$min,$hour,$monthday,$month,$year,$weekday,$yearday,$isdaylight)=localtime;
if ($min<10){$minute="0$min"}else{$minute=$min;}
##########################################################log activity.
$browser=$ENV{"HTTP_USER_AGENT"};
$host=$ENV{"REMOTE_HOST"};
$addr=$ENV{"REMOTE_ADDR"};

open(LOG,">>logfile.dat");
print LOG $month+1, '/', $monthday, '/', $year, $delm, $hour,':', $minute, $delm, $whichfile, $delm, '"', $in{'query'}, '"', $delm, $found, $delm, "Found", $delm, $browser, $delm, $host, $delm, $addr, $delm, "\n";
close LOG;
#####################

print "end";
__END__;

[edited by: phranque at 4:47 am (utc) on Feb 29, 2012]
[edit reason] edited to fix sidescroll [/edit]


Thread source:: http://www.webmasterworld.com/perl/4422787.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com