simple folder search

From: Ken Saunders (bnbliss_at_comcast.net)
Date: 11/19/04


Date: Thu, 18 Nov 2004 19:28:43 -0800

Below is the script I've been working on. I know theres something
wrong with it but can't find it for the life of me. I've made some
changes to tighen up the logic. Can someone help me get this running.
Its supposed to search my all of my files and return a page with the
matchs. I had this working as an html file and a cgi but when I tried
to merge the two it go broken. Thanks everyone

#!/usr/bin/perl
# Ken Saunders
#11/16/2004
#itc 216
#assignment 3
#this perl script displays a search form, and searchs for matchs on
html files

use strict;
use File::Find;
use CGI;

#variable - query
my $query = param("query");

# There's nothing in the query string
if ($query eq '')
 {
    print header();
    print start_html();

    # Displays the search form
    print q(<form action="./assign_3.cgi" method="post">);
    print q(<input type="text" name="query" size="50" />);
    print q(<input type="submit" />);
    print q(</form>);

    print end_html();

    # Bail out early if there are no results to print
    exit;

    #$filePath = $File::Find::name;
    #$filePath =~
s/(home\/classes\/ksaund01\/public_html)/~ksaund01/ig
 }

    #prints the header wiht the query name in an ordered list
    print header();
    print start_html();
    print "\n<p>For the query $query, these results were
    found:</p>\n<ol>\n";
    undef $/;

    #search
    find( sub
 {
    return if($_ =~ /^\./);
    return unless($_ =~ /\.html/i);
    stat $File::Find::name;
    return if -d;
    return unless -r;

    open(FILE, "< $File::Find::name") or return;
    my $string = <FILE>;
    close (FILE);

    return unless ($string =~ /\Q$query\E/i);
    my $page_title = $_;
    if ($string =~ /<title>(.*?)<\/title>/is)
 {
     $page_title = $1;
 }
  print "<li><a href=\"$File::Find::name\">$page_title</a></li>\n";
 },
  '/~ksaund01/page1.html');

  print "</ol>\n";
  print end_html();
End



Relevant Pages

  • Re: header("test"); does not display
    ... I didn't write this script, ... That manual does not explain what particular job it uses header() in ... query. ... I'll wake up some night a 3:27 and I'll shout "Eureka!" ...
    (comp.lang.php)
  • header error without whitespace issue
    ... existing .html file with .htaccess configured to parse php scripts. ... Research yields that the header needs to be loaded before anything. ... How do I safely extract this call from the existing script and place the ...
    (php.general)
  • Re: HELP! Need AD Query for Last login
    ... query the DCs in the USA domain, how would I modify the script? ... I'm new to VB script and making this simple modification is beyond me at ... >> ' Because the lastLogon attribute is not replicated, ... Then, for each Domain Controller, ADO is used to search the ...
    (microsoft.public.scripting.vbscript)
  • Re: LDAP query information
    ... a "Dim" statement. ... script is run. ... Microsoft MVP Scripting and ADSI ... Can you please provide me info on what to do with the below query? ...
    (microsoft.public.windows.server.scripting)
  • Re: LDAP query information
    ... execution of the vbscript? ... The error message indicates the line number in the script, ... Dim strBase, strFilter, strAttributes, strQuery, adoRecordset ... ' Construct LDAP syntax query. ...
    (microsoft.public.windows.server.scripting)