|
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
|