Perl help...if anyone knows it.

  • Thread starter skip0110
  • 2 comments
  • 583 views
5,178
United States
Worcester, MA
skip0110
I'd greatly appreciate any help here. Just started hacking together a quick little perl search script which is mostly copied from A List Apart. This is the first Perl I have written.

Basically, the code currently looks through all the files in a directory and lists them if they contain the $query (passed in POSTDATA). I'd like it to parse subdirectories too. I tried to do this with the recursive call find( \&d,$File::Find::name); but although it is "seeing" the subdirectories (prints stuff like "saw directory ../htdocs/scion/images") it is obviously not searching through them. What am I missing? I'm pretty much going blind looking at all this $_=~/^\.\ stuff. :lol:

Code:
#!/usr/bin/perl -w
use strict;
use File::Find;
use CGI qw(:standard);
my $query = param("query");
print header();
print start_html();
print "\n<p>For the query $query, these results were found:</p>\n<ol>\n";
undef $/;

find( \&d,'../htdocs');

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

sub d
{
 return if($_ =~ /^\./);
 if (-d) {
 print "saw directory $File::Find::name<br>\n";
 find( \&d,$File::Find::name);
 }
 return unless($_ =~ /\.html/i);
 stat $File::Find::name;
 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=\"http://www.carsource.org/index.php?$File::Find::name\">$page_title</a></li>\n";

}
Thanks in advance.
 
Is the recursive call Find incrementing a variable ?
Excuse my musing , I have just perused the thread smellysocks had of the jdbc driver , with his problem being not escaping a slash.
Is $string the recursion that closes before it elides the contents .
Really am shooting in the dark , so feel free to ignore .
 
Back