It prob never finds a title because its looking for the word TITLE. Add a 'i' to the regex where searing for it.
To solve your other problem look into the HTML::Parser especially their htext example.


Update:

Ohh well. I might as well post the code

Update2:

Updated the code to actually work
#!/usr/bin/perl -w use HTML::Parser; #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; } } #######instead of the above code use the CGI module. #HTML::Parser stuff. Stolen from the HTML::Parser package's htext #example my $keyword; my $hit; my $title; my %inside; sub htmltag { my($tag, $num) = @_; $inside{$tag} += $num; } sub htmltext { return if $inside{script} || $inside{style}; $title = $_[0] if ($inside{title}); $hit = 1 if ($_[0] =~ /$keyword/); } my $parser = HTML::Parser->new( 'api_version' => 3, 'handlers' => [start => [\&htmltag, "tagname, '+1'"], end => [\&htmltag, "tagname, '-1'"], text => [\&htmltext, "dtext"], ], 'marked_sections' => 1); $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/); $hit = 0; $title = ""; %inside = (); open(FILE, $file) || die "couldnt open $!"; $parser->parse(\*FILE)->eof; close(FILE); if($hit) { $title = $file unless ($title); print "<A HREF=/$file>$title</A><BR>"; $listed=1; } }


T I M T O W T D I

In reply to Re: Search Engine troubles by Cine
in thread 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.