K
Ken Saunders
first Thaks to all those folks that gave me pointers on the perl
script assignment I was doing. I managed to cobble it together. Now
that I've gotten it together I'm facing another challenge. the script
is working but won't return any search results. Here is the code can
someone tell me why I get no results page? I'm new at this and
already I've learned that Perl is really fun and amazingly frustrating
at the same time. Thanks
bnbliss
#!/usr/bin/perl
#this perl script performs a keyword search and displays the results
use strict;
use CGI qw
standard);
use File::Find;
# Root directory of my website
my $filePath = '/home/classes/ksaund01/public_html';
print header;
print start_html(-bgcolor=>'lightblue');
if( param('criteria') ) {
find(\&search_file, $filePath);
}
else {
display_menu();
}
print end_html;
# Subroutines
sub search_file {
my $query = param('query');
if( $_ !~ /html|txt$/o ) {
return();
}
open(IN, "$_") or warn "Can't open $_: $!\n";
while ( my $line = <IN> ) {
chomp($line);
# Remove HTML from the line
$line =~ s/\<.*?\>//g;
# Cleanup filenames and turn it them
# a valid relative URL so that it can be uesd
# as a link
my $uri = $File::Find::name;
$uri =~ s/^$filePath//;
$uri = "/$uri";
if( $line =~ /$query/o ) {
print "<A HREF=$uri>$_</A><BR>";
}
}
close(IN);
}
sub display_menu {
print start_form,
b('Search this site for:'),
br,
textfield(-name=>'criteria'),
br,
submit(-name=>'Search'),
end_form;
}
script assignment I was doing. I managed to cobble it together. Now
that I've gotten it together I'm facing another challenge. the script
is working but won't return any search results. Here is the code can
someone tell me why I get no results page? I'm new at this and
already I've learned that Perl is really fun and amazingly frustrating
at the same time. Thanks
bnbliss
#!/usr/bin/perl
#this perl script performs a keyword search and displays the results
use strict;
use CGI qw
use File::Find;
# Root directory of my website
my $filePath = '/home/classes/ksaund01/public_html';
print header;
print start_html(-bgcolor=>'lightblue');
if( param('criteria') ) {
find(\&search_file, $filePath);
}
else {
display_menu();
}
print end_html;
# Subroutines
sub search_file {
my $query = param('query');
if( $_ !~ /html|txt$/o ) {
return();
}
open(IN, "$_") or warn "Can't open $_: $!\n";
while ( my $line = <IN> ) {
chomp($line);
# Remove HTML from the line
$line =~ s/\<.*?\>//g;
# Cleanup filenames and turn it them
# a valid relative URL so that it can be uesd
# as a link
my $uri = $File::Find::name;
$uri =~ s/^$filePath//;
$uri = "/$uri";
if( $line =~ /$query/o ) {
print "<A HREF=$uri>$_</A><BR>";
}
}
close(IN);
}
sub display_menu {
print start_form,
b('Search this site for:'),
br,
textfield(-name=>'criteria'),
br,
submit(-name=>'Search'),
end_form;
}