I am having a few problems with a search on a DAT file using perl with some
embedded HTML.  I want to search for a keyword and display the results in a
certain format which I have done OK in perl, but I have to manually put the
search keyword  into the code, the only problem is that I cannot get perl to
get the keyword typed in and then do the search when I run the html.  Not
sure if that makes sense but in a nutshell I want to do a search and I want
perl to take the keyword and display the results.   Any help would be great
as I have looked everywhere on the net and read loads of documentation, any
amendments to my code if you know the answer would be most appreciated.

Below is my rather amateurish attempt at perl:



#!/usr/local/bin/perl



use cgi;
use strict;

print  <<"DOC";
content-type: text/html\n\n
<html>
<head>
  <title>Search Dat File</title>
 </head>
 <body bgcolor=#FFFFFF text=#000000>
  <center>
   <h1>Product Dat Search Engine</h1>
  </center>

 <p>
<hr size=7 width=75%><p>
<form method=POST action="http:/itmachine/testsearch.pl">
<center><table border>
<tr>
<th>Text to Search For: </th><th><input type=text name= "terms"
size=40><br></th>
</tr><tr>
<th>Boolean: <select name="boolean">
<option>AND
<option>OR
</select> </th> <th>Case <select name="case">
<option>Insensitive
<option>Sensitive
</select><br></th>
</tr><tr>
<th colspan=2><input type=submit value="Search!"> <input
type=reset><br></th>
</tr></table></form></center>
<hr size=7 width=75%><p>

</body></html>

DOC

my $filename = 'prod.dat' ;
open (DATAFILE, "<$filename")
  or die "$0: cannot open file \"$filename\" for reading: $!\n" ;

my (@record, @records) ;
while (<DATAFILE>) {
  tr/\r\n//d ;
  push @record, $_ ;
  if (@record == 11) {
    push @records, join ("\t", @record) ;
    @record = () ;
  }
}
close (DATAFILE) ;

#example data search below put for keyword as I cannot get perl to grab it
from the search

my $keyword = 'J0040';
 print "Content-type: text/html\n\n";
 print "<H3>RESULTS:</H3>";
  (print map {"<br>$_\n"} grep /\Q$keyword\E/, @records);
 print "<html></html>\n";

die "$0: incomplete record (line count = ", scalar @record, ") at end
+of file \"$filename.\"\n"
  unless @record == 0 ;





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to