|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Ok,
First of all, I am a beginner, so please bear with me as I am certaint his problem is insignificant from your higher perspective. I am attempting to install the free Simple Search script into my home page, www.tantris.net. The problem is, when I enter a query at www.tantris.net/search.html I get a server error. This is certainly because I have misconfigured and mismodified the search.pl script. One of the potential problems is that I have included a style sheet. I know that when using perl with "" it is important to put the " to indicate that this is not perl script. Could some similar action apply to the } brackets used in CSS? Any help is appreciated. When I try to use this script I get a server error. Thanks, the script follow, TantrisKB@hotmail.com #!/usr/bin/perl # Scripts Archive at: #http://www.worldwidemart.com/scripts/ # # Copyright 1996 Matthew M. Wright All Rights Reserved. # # # # Simple Search may be used and modified free of charge by anyone so long as # # this copyright notice and the comments above remain intact. By using this # # code you agree to indemnify Matthew M. Wright from any liability that # # might arise from it's use. # # Define Variables # $basedir = '/www'; $baseurl = 'http://www.tantris.net'; @files = ('*.htm'); $title = "PS - Search Results"; $title_url = 'www.tantris.net'; $search_url = 'http://www.tantris.net/search.html'; # Done # ############################################################################## # Parse Form Search Information &parse_form; # Get Files To Search Through &get_files; # Search the files &search; # Print Results of Search &return_html; sub parse_form { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @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; } } sub get_files { chdir($basedir); foreach $file (@files) { $ls = `ls $file`; @ls = split(/s+/,$ls); foreach $temp_file (@ls) { if (-d $file) { $filename = "$file$temp_file"; if (-T $filename) { push(@FILES,$filename); } } elsif (-T $temp_file) { push(@FILES,$temp_file); } } } } sub search { @terms = split(/s+/, $FORM{'terms'}); foreach $FILE (@FILES) { open(FILE,"$FILE"); @LINES = <FILE>; close(FILE); $string = join(' ',@LINES); $string =~ s/n//g; if ($FORM{'boolean'} eq 'AND') { foreach $term (@terms) { if ($FORM{'case'} eq 'Insensitive') { if (!($string =~ /$term/i)) { $include{$FILE} = 'no'; last; } else { $include{$FILE} = 'yes'; } } elsif ($FORM{'case'} eq 'Sensitive') { if (!($string =~ /$term/)) { $include{$FILE} = 'no'; last; } else { $include{$FILE} = 'yes'; } } } } elsif ($FORM{'boolean'} eq 'OR') { foreach $term (@terms) { if ($FORM{'case'} eq 'Insensitive') { if ($string =~ /$term/i) { $include{$FILE} = 'yes'; last; } else { $include{$FILE} = 'no'; } } elsif ($FORM{'case'} eq 'Sensitive') { if ($string =~ /$term/) { $include{$FILE} = 'yes'; last; } else { $include{$FILE} = 'no'; } } } } if ($string =~ /<title>(.*)</title>/i) { $titles{$FILE} = "$1"; } else { $titles{$FILE} = "$FILE"; } } } sub return_html { print "Content-type: text/htmlnn"; print "<html>n"; print "<head>n"; print "<title>PS - Search Results</title>n"; print "<style>n"; print "div { font: 12pt/20pt comic sans ms, comic sans, arial, helvetica, sans-serif; margin-left: 1cm; margin-right: 1cm; text-align: justify }n"; print "div.2 { font: 10pt/15pt comic sans ms, comic sans, arial, helvetica, sans-serif; margin-left: .5cm; text-align: left }n" print "em { color: red; font-style: normal; font-weight: bold; font-size: 14pt }n"; print "em.sign { color: black; font-style: normal; font-weight: bold; font-size: 14pt }n"; print "A:link { color: red; font-weight: bold; text-decoration: none; font-size: 11pt }n"; print "A:visited { color: #993300; font-weight: bold; text-decoration: none; font-size: 11pt }n"; print "A:active { color: blue; font-weight: bold; text-decoration: none; font-size: 11pt }n"; print "</style>n"; print "</head>n"; print "<body text="#000000" bgcolor="#CC9966" link="#0000FF" vlink="#551A8B" alink="#0000FF">n"; print "<div>n"; print "<center>n <em>Results of Search in $title</em>n </center>n"; print "Below are the results of your Search in no particular order:<p><hr size=7 width=75%><p>n"; print "</div>n"; print "<ul>n"; foreach $key (keys %include) { if ($include{$key} eq 'yes') { print "<li><a href="$baseurl$key">$titles{$key}</a>n"; } } print "</ul>n"; print "<hr size=7 width=75%>n"; print "Search Information:<p>n"; print "<ul>n"; print "<li><b>Terms:</b> "; $i = 0; foreach $term (@terms) { print "$term"; $i++; if (!($i == @terms)) { print ", "; } } print "n"; print "<li><b>Boolean Used:</b> $FORM{'boolean'}n"; print "<li><b>Case $FORM{'case'}</b>n"; print "</ul><br><hr size=7 width=75%><P>n"; print "<ul>n<li><a href="$search_url">Back to Search Page</a>n"; print "<li><a href="$title_url">$title</a>n"; print "</ul>n"; print "<hr size=7 width=75%>n"; print "</body>n</html>n"; } |
|
#2
|
|||
|
|||
|
Yep...
use the quote operator qq// or q// when you include a lot of complex code to print... look up the differences between the two, basically, qq// will interpolate any variables you hae within the text, while q// won't... If you are just printing the straight text, it's safer to use the latter... |
|
#3
|
|||
|
|||
|
When debugging CGI scripts it sometimes helps to run the script from the command line with -w e.g. perl -w script.cgi
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by ryanh: Yep... use the quote operator qq// or q// when you include a lot of complex code to print... look up the differences between the two, basically, qq// will interpolate any variables you hae within the text, while q// won't... If you are just printing the straight text, it's safer to use the latter...[/quote] |
|
#4
|
|||
|
|||
|
Why dont you just place the style sheet in an external file and include:
print "<LINK REL="stylesheet" TYPE="text/css" HREF="/mystyle.css">n"; Hope this help, good luck |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Beginner - Simple Search Script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|