Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 11th, 2000, 10:16 AM
Tantris Tantris is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Location: NY, NY, USA
Posts: 2 Tantris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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";
}

Reply With Quote
  #2  
Old February 5th, 2000, 05:48 AM
ryanh ryanh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 1999
Posts: 119 ryanh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 41 sec
Reputation Power: 14
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...

Reply With Quote
  #3  
Old March 9th, 2000, 12:26 PM
samplecode samplecode is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 7 samplecode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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]


Reply With Quote
  #4  
Old March 18th, 2000, 07:45 PM
DrFaustus DrFaustus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 8 DrFaustus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to DrFaustus
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Beginner - Simple Search Script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap