D Borland wrote:
....
I am looking to create database (probably) using SQLlite and perl and it's
interface. What i would like to know is there any way with perl for me to
create a simple server, so i could say open a local file form the harddrive
in my webbrowser, then click on a link to execute a perl script which will
in turn return data to the current browser process. ....
D Borland
....
It isn't very good, but it is an all-Perl web server. Put it in the
same directory as your HTML files (*.html) and Perl CGI files (*.cgi):
use HTTP:

aemon;
use IPC::Open2;
$|=1;
my $server=HTTP:

aemon->new(LocalPort=>80,LocalAddr=>'localhost');
print "Please contact me at <URL:", $server->url, ">\n";
while($client=$server->accept){
while(my $answer=$client->get_request){
$ans=$answer->as_string;
@ans=split /\n/,$ans;
$client->autoflush;
if($answer->method eq 'GET'){
$path=$answer->url->path;
(error,last) unless $path=~s#^/##;
if($path=~/html$/i){
$client->send_file_response($path);
last;
}
if($path=~/cgi$/i){
$ENV{REQUEST_METHOD}=$answer->method;
$query=$answer->url->query;
$ENV{CONTENT_LENGTH}=length($query);
$ENV{QUERY_STRING}=$query;
$out=`perl $path`;
$out=~s/.*?\n\n//s; #remove HTTP header
print $client $out;
last;
}
}
if($answer->method eq 'POST'){
$path=$answer->url->path;
(error,last) unless $path=~s#^/##;
if($path=~/cgi$/i){
$query=$answer->url->query;
$ENV{REQUEST_METHOD}=$answer->method;
for(@ans){
$ENV{CONTENT_LENGTH}=$1 if /Content-Length: (\d+)/;
$ENV{HTTP_REFERRER}=$1 if /Referer: (.*)/;
}
$query=$ans[-1];
undef $CGI;undef $OUT;
$pid=open2($CGI,$OUT,"perl","$path") or error;
print $OUT $query;
close $OUT;
@out=<$CGI>;
waitpid $pid,0;
$out=join "\n",@out;
$out=~s/.*?\n\n//s; #remove HTTP header
print $client $out;
last;
}
}
last;
}
print "CLOSE: ", $client->reason, "\n" if $client->reason;
undef $client;
}
sub error{
$client->error(RC_FORBIDDEN);
print "An error occurred in $ans\n";
}