Gossamer Forum
Home : General : Perl Programming :

Error in CGI\Perl.....

Quote Reply
Error in CGI\Perl.....
Hi,
I have written a Perl-CGI program(address.pl) which is linked to my HTML page(cgi.htm) . And my data file (dumb.pdb)is linked to Perl-CGI program.but when I submit my query then its just display the whole code of my Perl-CGI program.....

Sometimes ,I got HTTP error 404.I dn't know why is it creating error .
My all the programs are located in cgi-bin and the module cgi-lib.pl which I have downloaded is also located in cgi-bin.

Any help is really Appreciated.....
Thanks in advance.....

perl code (address.pl):

use CGI;
require "cgi-lib.pl";

# grab values passed from form:
&ReadParse(*in);
print "Content-type: text/html\n\n";
# print the top part of the response
print "<HTML><HEAD><TITLE>Addresss Book Search Results</TITLE></HEAD>\n";
print "<BODY><H1>Addresss Book Search Results</H1>\n";
# read and parse data file
$data="dumb.pdb";
open(DATA,"$data") || die "Can't open $data: $!\n</BODY></HTML>\n";
while(<DATA>) {
chop; # delete trailing \n
if (/^\s*$/) {
# break between records
if ($match) {
# if anything matched, print the whole record
&printrecord($record);
$nrecords_matched++;
}
undef $match;
undef $record;
next;
}
# tag: value
($tag,$val) = split(/:/,$_,2);
if ($tag =~ /^structureId/i) {
$match++ if( $in{'structureId'} && $val =~ /\b$in{'structureId'}\b/i) ;
$record = $val;
next;
}


}
# anything else
$record .= $_;
close DATA;
if (! defined $nrecords_matched)
{ print "<H2>No Matches</H2>\n"; }
print "</BODY></HTML>\n";
exit;
sub printrecord {
local($buf) = @_;
print "<P>\n$buf<P>\n";
}


HTML code (cgi.htm):

<html>
<head>
<body bgcolor=white>
<marquee>
<H1 align = "center"><font size=4><font color="blue">SEARCH FOR PROTEIN COMPLEXES</font></font></H1>
</marquee>
<HR>
<FORM METHOD="GET" ACTION="address.pl">
<H3><H1 align = "center"><font color="blue">Search for links: </font><H1></H3>
<input type="text"name="search" size="25" MAXLENGTH="30">
<input type="submit" value="submit search">
<input type="reset" value="clear form">
<br></br>
<br></br>
<img src="C:\Documents and Settings\Desktop\icsd.gif"width="300" height="150" align="center">
</FORM>
</body>
</html>
Quote Reply
Re: [sanchika] Error in CGI\Perl..... In reply to
See the modern CGI module for appropriate modern usage (i.e., without the 'require cgi-lib.pl'). Also see 'local' (for proper usage) and 'exit' (for useful usage notes) in perldoc.

FYI, where you used it, 'die' basically does 'print STDERR @_' and 'exit ($! || $? >> 8 || 255)'. In other words, your 'die "Can't open $data: $!\n</BODY></HTML>\n";' will never send the "Can't open..." part to your browser because the web server only looks at STDOUT for what to send browsers. Consider 'use CGI::Carp q/fatalsToBrowser/;' instead.

IMO, 'marquee's are annoying (even where supported) and should never be used. And your image will never display except on local systems with the file at that location.
....
With regard to your question, how are you accessing your script? When you submit, are do you see 'file:///' are the beginning of your location bar or do you see 'http://'? If you are using Konqueror, you can configure it to execute CGI programs locally, but judging by the 'C:\' Windows-style paths you probably are not.

Whether you are using Konqueror or not, the best way you to run CGI programs is using a properly configured web server (such as the Apache HTTP Server).

Quote Reply
Re: [mkp] Error in CGI\Perl..... In reply to
Thanx Sir for considering my request .I have downloaded CGI.pm module but its creating some problem in installing .Presently I'm working on Windows XP with Apache server.Please tell me if any extensions have to be added?
I have changed a bit my program...


use CGI::Apache;
use CGI::Carp qw(carpout);
require "cgi-lib.pl";

# grab values passed from form:
&ReadParse(*in);
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";
# print the top part of the response
print "<HTML><HEAD><TITLE>Addresss Book Search Results</TITLE></HEAD>\n";
print "<BODY><H1>Addresss Book Search Results</H1>\n";
# read and parse data file
BEGIN {
#$data=">>C:\Program Files\Apache Group\Apache\cgi-bin\res.pdb";
use CGI::Carp qw(carpout);
open(DATA,">>C:\Program Files\Apache Group\Apache\cgi-bin\res.pdb") || die ("Unable to open res.pdb: $!\n");
carpout(DATA);
}
print "</BODY></HTML>\n";
while(<DATA>) {
chop; # delete trailing \n
if ($match) {
# break between records
if ($match) {
# if anything matched, print the whole record
&printrecord($record);
$nrecords_matched++;
}
undef $match;
undef $record;
next;
}
# tag: value
($tag,$val) = split(/:/,$_,2);
if ($tag =~ /^structureId/i) {
$match++ if( $in{'structureId'} && $val =~ /\b$in{'structureId'}\b/i) ;
$record = $val;
next;
}


}
# anything else
$record .= $_;
close DATA;
if (! defined $nrecords_matched)
{ print "<H2>No Matches</H2>\n"; }
print "</BODY></HTML>\n";
exit;
sub printrecord {

local($buf) = @_;
print "<P>\n$buf<P>\n";
}


Error is unable to open res.pdb

please help me out......
Quote Reply
Re: [sanchika] Error in CGI\Perl..... In reply to
Code:
open(DATA,">>C:\Program Files\Apache Group\Apache\cgi-bin\res.pdb") || die ("Unable to open res.pdb: $!\n");
If that fails, you probably do not have access to create or access that file. This could be your Apache or system configuration. What does $! contain?
Quote Reply
Re: [mkp] Error in CGI\Perl..... In reply to
hi,
thanks for solving my problem. Now I`m facing a different one. I have a data file from which I need to extract only the link of the protein and their titles. To achieve this I did the following.
I built up an HTML page in which the user will enter the id of interest via PERL programming. That id will be searched in my data file and then the related links should be displayed back as the output. I hope I have made myself clear. Can you please guide me. I am sending you a part of my data file and the HTML page.
-sanchika

res.pdb(data file)

<a href=http://www.rcsb.org/pdb/explore.do?structureId=1OA5
THE SOLUTION STRUCTURE OF BOVINE PANCREATIC TRYPSIN INHIBITOR AT HIGH PRESSURE
</a>

<a href=http://www.rcsb.org/pdb/explore.do?structureId=1OA6
THE SOLUTION STRUCTURE OF BOVINE PANCREATIC TRYPSIN INHIBITOR AT HIGH PRESSURE
</a>

<a href=http://www.rcsb.org/pdb/explore.do?structureId=1UUA
SOLUTION STRUCTURE OF A TRUNCATED BOVINE PANCREATIC TRYPSIN INHIBITOR, 3-58 BPTI
</a>

.............etc etc

cgi.htm(html page)

<html>
<head>
<body bgcolor=white>
<H1 align = "center"><font size=4><font color="blue">SEARCH FOR PROTEIN COMPLEXES</font></font></H1>
<HR>
<FORM METHOD="GET" ACTION="http://localhost/cgi-bin/try.pl">
<H3><H1 align = "center"><font color="blue">Search for links: </font><H1></H3>
<input type="text"name="search" size="25" MAXLENGTH="30">
<input type="submit" value="submit search">
<input type="reset" value="clear form">
<br></br>
<br></br>
<img src="C:\Documents and Settings\birla\Desktop\icsd.gif"width="300" height="150" align="center">
</FORM>
</body>
</html>
Quote Reply
Re: [sanchika] Error in CGI\Perl..... In reply to
I started writing a response and then I realized you didn't provide some of the most important information: what is the problem? What did you try that didn't work (code)?

Is that sample you provided a sufficient description of the entire file (i.e., does it follow exactly that format)? Etc, etc?
Quote Reply
Re: [mkp] Error in CGI\Perl..... In reply to
Hello,
I`am sorry. The problem is when I type the id in my HtMl page it should give the links and the title of the id. I will try to make my problem clear to you. I have all the links stored in a particular file. Out of these couple of links I need only a few for every id that the user has asked for But the problem is, it is not able to extract the link of the the desired id. Kindly guide me how to extract links via PERL programming. Regarding the format the sample that I have sent you are the links of few ids that I want to be printed as an output.
Thanks,
Quote Reply
Re: [sanchika] Error in CGI\Perl..... In reply to
Look, if you have a specific problem, I can help you. But if you don't even try it, I don't know where you need help - and me writing your code for you does not really help anyone.

Try it and if you have an issue you really can't figure out, I can maybe help you out.