Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone perl me? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
shake & bake (Visitor) Mar 6, 2001
Hey All,

I'm new to Perl and could surely use your help. I've created a script and placed it in my cgi-bin, however, I get the following error message instead: Premature end of script handler /data1/hm/harmani.com/cgi-bin/form.cgi

At present, my form is located at
the following is my script:
#!/usr/local/bin/perl
&get_form_data();
&send_email;
&print_thankyou_page;
sub get_form_data
{

#Get the input

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

#Split the name-value pairs
@parirs=split(/&/, $buffer);
foreach $pair (@paris)

{

($name, $value)=split(/=/, $pair);
#Un-Webify plus signs and %-encoding

$value=~tr/+/ /;
$value=~s/%[a-fA-FO-9][a-fA-FO-9])/pack("C",
hex($!))/eg;
$value=~s/<!--(.|\n)*-->//g;
$FORM($name)=$value;
}
}
sub send_email
{
$to=&quot;ceo\@harmani.com&quot;;
open(MAIL, &quot;/var/qmail/bin/qmail-inject -t $to&quot;) || die
(&quot;can't open sendmail&quot;);
print MAIL &quot;From: $FORM{'email'}\n&quot;;
print MAIL &quot;To: $to\n&quot;;
print MAIL &quot;Subject: Form submission\n\n&quot;;
# print out the form results
print MAIL &quot;Name: $FORM{'Name1'}\n&quot;;
print MAIl &quot;Title: $FORM{'Title'}\n;
print MAIL &quot;E-mail: $FORM{'Email'}\n;
print MAIL &quot;Address: $FORM{'Address'}\n;
print MAIL &quot;Gender: $FORM{'Gender'}\n;
print MAIL &quot;Age: $FORM{'Age}\n;
print MAIL &quot;Date of Birth: $FORM{'DOB'}\n;
print MAIL &quot;How did you find out about Harmani?: $FORM{'Info1'}\n;
print MAIL &quot;What is it that you like about Harmani?: $FORM{'Info2'}\n;
print MAIL &quot;What would you like to see improved at Harmani?: $FORM{'Comment'}\n;
close (MAIL);
}
sub print_thankyou_page
{
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML>\n<HEAD>\n<BODY BGCOLOR=\&quot;#FFFF99\&quot;>\n
</HEAD>&quot;;
print &quot;<H3>Thank you</H3>\n\n&quot;;
print &quot;<P>\n&quot;;
print &quot;Thank you for your submission\n&quot;;
print &quot;<P>\n&quot;;
print &quot;<A HREF=\&quot; the home page\n&quot;;
}
print &quot;</BODY<\n</HTML>&quot;;
 
This code has a mulitude of syntax errors. I'll list a couple....

In,
$value=~s/%[a-fA-FO-9][a-fA-FO-9])/pack(&quot;C&quot;,hex($!))/eg;
the O-9 has an alpha char that comes after 'N' and before 'P' where it needs a zero. Thus the range [red]O[/red]-9 is non-sensical. It should be zero - nine, 0-9.

Many of the print statements lack closing quotes,
print MAIl &quot;Title: $FORM{'Title'}\n;
should be,
print MAIl &quot;Title: $FORM{'Title'}\n[red]&quot;[/red];

These types of errors are easily identified using 'perl -c form.cgi'. The '-c' tells the interpreter to do a syntax check,but don't run the code. The errors that are produced do not necessarilly tell you exactly what is wrong, but they will give you a good idea about where to look and the type of syntax errors you have should be easy to find.


HTH


keep the rudder amid ship and beware the odd typo
 
Thanks 'goboating' for always keeping the lookout for me. However, my ship is about to go aground. I have since modified my script, but I continue to keep the same course. How can I navigate myself to the right direction? Do I have to include input type hidden tags into my form? Or, is there any easier way to right my script with the same results?

shake & bake
 
Do you have telnet access to the server? If so, work at the command line to get the syntax valid. Once that is done, we can go at it via a browser<->web server approach.

When you make a request of a web server for a page, the web server must send back a compliant header to the browser. In static HTML, the web server does this on it own. With CGI stuff, the cgi code must do this.
It is this stuff
Code:
-->&quot;Content-type: text/html\n\n&quot;;
The 'premature end of script header' complaint indicates that the cgi did not produce a compliant header. So, either that line is incorrect in your code ( it looks ok to me) or the cgi code is blowing up before it sends the header, which is what I expect is happeing. If you have telnet access to the server that is running the code, then work with the code using 'perl -c form.cgi' until you fix all of the syntax problems. That does not mean the code will do what you want. It just means the code will run. Once the syntax works you can move on to making it work via the web.


HTH


keep the rudder amid ship and beware the odd typo
 
Hey goboating,

It's me again, shake & bake. I did a cgi error check and this is what came up:

/%[a-fA-F0-9][a-fA-F0-9])/: unmatched () in regexp at form.cgi line 23.
syntax error at form.cgi line 23, near &quot;$FORM(&quot;
Bad name after DOB' at form.cgi line 41.
syntax error at form.cgi line 23, near &quot;$FORM(&quot;
Execution of form.cgi aborted due to compilation errors.
syntax error at form.cgi line 23, near &quot;$FORM(&quot;
Execution of form.cgi aborted due to compilation errors.

I have since re-modified the script to the following, but still no luck:
#!/usr/local/bin/perl
&get_form_data();
&send_email;
&print_thankyou_page;
sub get_form_data
{

#Get the input

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

#Split the name-value pairs
@parirs=split(/&/, $buffer);
foreach $pair (@paris)

{

($name, $value)=split(/=/, $pair);
#Un-Webify plus signs and %-encoding

$value=~tr/+/ /;
$value=~s/<!--(.|\n)*-->//g;
$FORM($name)=$value;
}
}
sub send_email
{
$to=&quot;ceo\@harmani.com&quot;;
open(MAIL, &quot;/var/qmail/bin/qmail-inject -t $to&quot;) || die
(&quot;can't open sendmail&quot;);
print MAIL &quot;From: $FORM{'email'}\n&quot;;
print MAIL &quot;To: $to\n&quot;;
print MAIL &quot;Subject: $FORM submission\n\n&quot;;
print MAIL &quot;Name: $FORM{'Name1'}\n&quot;;
print MAIl &quot;Title: $FORM{'Title'}\n&quot;;
print MAIL &quot;E-mail: $FORM{'Email'}\n&quot;;
print MAIL &quot;Address: $FORM{'Address'}\n&quot;;
print MAIL &quot;Gender: $FORM{'Gender'}\n&quot;;
print MAIL &quot;Age: $FORM{'Age'}\n&quot;;
print MAIL &quot;Date of Birth: $FORM{'DOB'}\n&quot;;
print MAIL &quot;How did you find out about Harmani?: $FORM{'Info1'}\n&quot;;
print MAIL &quot;What is it that you like about Harmani?: $FORM{'Info2'}\n&quot;;
print MAIL &quot;What would you like to see improved at Harmani?: $FORM{'Comment'}\n&quot;;
close (MAIL);
}
sub print_thankyou_page
{
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML>\n<HEAD>\n<BODY BGCOLOR=\&quot;#FFFF99\&quot;>\n
</HEAD>&quot;;
print &quot;<H3>Thank you</H3>\n\n&quot;;
print &quot;<P>\n&quot;;
print &quot;Thank you for your submission\n&quot;;
print &quot;<P>\n&quot;;
print &quot;<A HREF=\&quot; the home page\n&quot;;
}
print &quot;</BODY<\n</HTML>&quot;;


shake & bake
 
Here is a syntactically correct version. I went back the code in your previous post, because you can not do without some of what you deleted, like...
$value=~s/%[a-fA-FO-9][a-fA-FO-9])/pack(&quot;C&quot;,hex($!))/eg;

About the errors you listed...
$value=~s/%[a-fA-FO-9][a-fA-FO-9][red])[/red]/pack(&quot;C&quot;,hex($!))/eg;
That has an extraneous ')'.

syntax error at form.cgi line 23, near &quot;$FORM(&quot;
Bad name after DOB' at form.cgi line 41.
When working with hashes (associative arrays) use squirrelly braces, like
$FORM[red]{[/red]element_name[red]}[/red];

I did not run this to see if it works. I only did 'perl -c program' to find the syntax errors. If you have further problems, we can deal with the logic later. I don't mean to preach, but this is pretty basic stuff. A little reading would go a long way here.


#!/usr/local/bin/perl
&get_form_data();
&send_email;
&print_thankyou_page;
sub get_form_data
{
#Get the input
read(STDIN, $buffer,$ENV{'Content_Length'} );
#Split the name-value pairs
@parirs=split(/&/, $buffer);
foreach $pair (@paris)
{
($name, $value)=split(/=/, $pair);
#Un-Webify plus signs and %-encoding
$value=~tr/+/ /;
# $value=~s/%[a-fA-F[red]O[/red]-9][a-fA-F[red]O[/red]-9][red])[/red]/pack(&quot;C&quot;,hex($!))/eg;
$value=~s/%[a-fA-F0-9][a-fA-F0-9]/pack(&quot;C&quot;,hex($!))/eg;
$value=~s/<!--(.|\n)*-->//g;
# $FORM[red]([/red]$name[red])[/red]=$value;
$FORM{$name}=$value;
}
}
sub send_email
{
$to=&quot;ceo\@harmani.com&quot;;
open(MAIL, &quot;/var/qmail/bin/qmail-inject -t $to&quot;) || die
(&quot;can't open sendmail&quot;);
print MAIL &quot;From: $FORM{'email'}\n&quot;;
print MAIL &quot;To: $to\n&quot;;
print MAIL &quot;Subject: Form submission\n\n&quot;;
# print out the form results
print MAIL &quot;Name: $FORM{'Name1'}\n&quot;;
# print MAIl &quot;Title: $FORM{'Title'}\n;[red]missing &quot;[/red]
print MAIl &quot;Title: $FORM{'Title'}\n&quot;;
# print MAIL &quot;E-mail: $FORM{'Email'}\n;[red]missing &quot;[/red]
print MAIL &quot;E-mail: $FORM{'Email'}\n&quot;;
# print MAIL &quot;Address: $FORM{'Address'}\n;[red]missing &quot;[/red]
print MAIL &quot;Address: $FORM{'Address'}\n&quot;;
# print MAIL &quot;Gender: $FORM{'Gender'}\n;[red]missing &quot;[/red]
print MAIL &quot;Gender: $FORM{'Gender'}\n&quot;;
print MAIL &quot;Age: $FORM{'Age'}\n&quot;;# [red]missing &quot; and ' after Age[/red]
# print MAIL &quot;Date of Birth: $FORM{'DOB'}\n;[red]missing &quot;[/red]
print MAIL &quot;Date of Birth: $FORM{'DOB'}\n&quot;;
print MAIL &quot;How did you find out about Harmani?: $FORM{'Info1'}\n&quot;;# [red]missing &quot;[/red]
print MAIL &quot;What is it that you like about Harmani?: $FORM{'Info2'}\n&quot;;# [red]missing &quot;[/red]
print MAIL &quot;What would you like to see improved at Harmani?:$FORM{'Comment'}\n&quot;;# [red]missing &quot;[/red]
close (MAIL);
}
sub print_thankyou_page
{
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML>\n<HEAD>\n<BODY BGCOLOR=\&quot;#FFFF99\&quot;>\n</HEAD>&quot;;
print &quot;<H3>Thank you</H3>\n\n&quot;;
print &quot;<P>\n&quot;;
print &quot;Thank you for your submission\n&quot;;
print &quot;<P>\n&quot;;
print &quot;<A HREF=\&quot; the home page\n&quot;;
}
print &quot;</BODY<\n</HTML>&quot;;


I hope this helps....


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top