I am more of a PERL user than a PERL writer and I have a problem that I cannot figure out. I am very limited in PERL experience so the solution could be very obvious. I am using a search engine in PERL to search my site. I really like how it works but unfortunately, it searches the html document and gives me results based on things such as links and even Javascript. I would consult the original writer of the code but I downloaded it from a site a couple days ago and forgot where I got it. Here is the code, important and unimportant. Im praying I use the code tags right.
#!/usr/bin/perl #The following code deals with the form data if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs =split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name}= $value; } } $keyword=$FORM{keyword}; print "Content-type: text/html\n\n"; print "<h2> Here are the files we found</h2>\n\n"; chdir("/usr/local/etc/httpd"); opendir(DIR, "."); while($file = readdir(DIR)) { next if ($file !~ /.htm/); open(FILE, $file); $foundone = 0; $title = ""; while (<FILE>) { if (/$keyword/i) { $foundone = 1; } if (/<TITLE>/) { chop; $title = $_; $title =~ s/<TITLE>//g; $title =~ s/<\TITLE>//g; } } if ($title eq "") { $title = $file; } if($foundone) { print "<A HREF=/$file>$title</A><BR>"; $listed=1; } close(FILE);
After that it just prints out some default stuff and exits. But like I said its giving html and javascript results and really the only way I can think of changing that is to ignore everything in between the head tags (for javascript) and the tags (for the links which are my main problems). I hope I have made some sense here. Like I said, I'm more of a reader than a writer. I understand almost every line of this code, I just don't know how to correctly alter it. On a side note, the program also never prints out the title and istead prints the name of the file every time but thats not my biggest concern right now. If you have any advice on either of them I would appreciate it. Thanks. Divinus

In reply to Search Engine troubles by divinus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.