Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 30th, 2004, 12:58 PM   #1
jin_how
Newbie
 
Join Date: Oct 2004
Posts: 1
Rep Power: 0 jin_how is on a distinguished road
Send a message via ICQ to jin_how
i need help to solve the script that i have here. i need to write a Perl script that enables user to type some keywords to search. basically i have 3 files - example.html (form), search.pl and info.sgl

info.sgl stores information of articles and has structure like this:

<ref>
<provnc>
<aulist>
<author>Paul-Michael Agapow</author>
</aulist>
<year>1995</year>
<source>-
<id>pmaevol
<keywords>
<key>computational ecosystem</key>
</keywords>
</provnc>
<title>Bootstrapping Evolution with Extra-Somatic Information</title>
<abstract>
<para>--sentences goes here--</para>
</abstract>
</ref>
#################################################
#!/usr/bin/perl
use CGI ':standard';

print "Content-type:text/html\n\n";

my %data;

print <<End_of_head;
<html>
<head><title>Display Results</title></head>
<body>



<h4>Search Results</h4>


End_of_head

open (FILE, "<data.sgl") or die("Unable to open data.sgl\n");

while(<FILE> ) {

if (/\<author\>\s*(\D*)/gi)
{
&parse_form;
&get_data;
&print_data;
}
}

print <<End_of_Doc;
</body>
</html>
End_of_Doc

sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@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_data {


while(<FH> ) {

$data{author} = $1 if /\<author\>\s*(\D*)/i;
$data{year} = $1 if /\<year\>\s*(\d{4})/i;
$data{source} = $1 if /\<source\>\s*(\D*)/i;
$data{id} = $1 if /\<id\>\s*(\d+)/i;
$data{key} = $1 if /\<key\>\s*(\D*)/i;
$data{title} = $1 if /\<title\>\s*(\D*)/i;
$data{para} = $1 if /\<para\>\s*(\D*)/i;

return if /\<\/ref\>/;
}
}

sub print_data{

print <<End_of_print;


Author:$data{author}
Year: $data{year}
Source: $data{source}
Keywords: $data{key}
Title: $data{title}
Abstract: $data{para}


<hr>
End_of_print

}

close(FH);
####################################################
the program should read in the author name and search in the data.sgl. if the author name is found then that author article information (author name, year, source, keywords, title and abstract) is displayed. when i upload the files to the server, it never works.

help is appreciated.
__________________
jinhow
jin_how is offline   Reply With Quote
Old Oct 31st, 2004, 2:33 PM   #2
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Could you elaborate? Any ideas why it is not working, or where the code might be failing?
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC