Dear friends,
A year or two ago I designed a Perl search engine as an assignment. The trouble is I promised a friend I would go through it with them as they have interests in Perl programming through their job. I would be extremely grateful if someone could add a few brief comments to the following Perl code so that I could print it off and hand it to my friend. I think the best way of doing this would be to add comments in the following format alongside any relevant part of the code.( //what this does etc etc.... ).
I would be so grateful for any feedback.
Thanks.
------------------------------------------------------------
#!c:perlinperl.exe
use CGI ':all';
print header();
print start_html();
$file = param('result');
$search = param('word');
($sec, $min, $hour, $day, $month, $year) = (localtime) [0,1,2,3,4,5];
$year=$year+1900;
open(FILE,"$file");
open (LOGFILE,">>h:/Data/log/logfile.txt");
print LOGFILE"$file $day-$month-$year $hour-$min-$sec '$search'
";
print"
$file";
while ()
{
print"$_";
print"
";
}
close(LOGFILE);
close(FILE);
print end_html();
-------------------------------------------------------------
#!c:perlinperl.exe
use CGI ':all';
print header();
print start_html();
$search = param('words');
@rfc_file = glob("h:/data/Rfc/"."*.txt");
foreach $file (
@rfc_file){
open (FILE, $file);
while()
{
if ($_ =~ /$search/)
{
print"
$file";
}
}
}
close(LOGFILE);
print end_html();
-------------------------------------------------------------
#!c:perlinperl.exe
use CGI ':all';
print header();
print start_html();
print"";
print"
";
print"
";
open (LOGFILE, "/data/log/logfile.txt");
while()
{
print"";
print"";
@word=split(/ /,$_);
print"";
print"$word[0]";
print"$word[1]";
print"$word[2]";
print"$word[3]";
print"";
}
print"";
print"";
print"";
close(LOGFILE);
print end_html();
------------------------------------------------------------
As mentioned, this is for a search engine using Perl and HTML. The search engine searches through a selection of RFC's and returns a list of the RFC's that contain the desired word. Then it is possible to view a log of all searched files which displays the time, filename, and keyword searched for. It also has a simple password system if that is relevant.
I would hugely appreciate any swift response!!
Thanks again.
I look forward to hearing from you all.
Comments
use CGI ':all'; #imports modules for cgi
print header(); #begins by printing the head tags( etc. #to the users computer
print start_html(); #continues writing, but with body, etc
$file = param('result'); #sets variable file to the user input named #result
$search = param('word'); #sets variable search equal to user input #named word
($sec, $min, $hour, $day, $month, $year) = (localtime) [0,1,2,3,4,5]; #gets the time, and sets it equal to variable sec, min, hour, day etc
$year=$year+1900; #gets the 2 number variable, and adds 1900 to #it(to make it a real year) and then assigns it to variable year
open(FILE,"$file"); #this opens a new file(can be reffered to as #"FILE", its name is the varibale file, which is input from the #user(or hidden field
open (LOGFILE,">>h:/Data/log/logfile.txt"); #opens another file,
#notice the >> before the filename, which means "append" access #privilages
print LOGFILE"$file $day-$month-$year $hour-$min-$sec '$search'
"; #prints information about time, day, etc to LOGFILE
print"$file"; #prints variable file to the userers browser
while () #while the file, named "FILE" is still defined(ie it is reading character by character, and it isn't the last character)
{
print"$_"; #print the character in while, this is used to print the contents of the file "FILE" onto the users browser
print"
";
}
close(LOGFILE); #CLOSES OUTPUT STREAM TO LOGFILE
close(FILE); #CLOSES OUTPUT STREAM TO FILE
print end_html(); #prints closing body/html/etc to users browser
---------------------------------------------------------------
i finished the first part, copy it into simpletext, turn wordwrap off, and it will look better