×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Can anyone perl me?

Can anyone perl me?

Can anyone perl me?

(OP)
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 http://www.harmani.com/feedback/form.html

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

RE: Can anyone perl me?

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("C",hex($!))/eg;
the O-9 has an alpha char that comes after 'N' and before 'P' where it needs a zero.  Thus the range O-9 is non-sensical.  It should be zero - nine, 0-9.

Many of the print statements lack closing quotes,
print MAIl "Title: $FORM{'Title'}\n;
should be,
print MAIl "Title: $FORM{'Title'}\n";

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

RE: Can anyone perl me?

(OP)
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

RE: Can anyone perl me?

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 -->"Content-type: text/html\n\n";
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

RE: Can anyone perl me?

(OP)
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 "$FORM("
                          Bad name after DOB' at form.cgi line 41.
                          syntax error at form.cgi line 23, near "$FORM("
                          Execution of form.cgi aborted due to compilation errors.
                          syntax error at form.cgi line 23, near "$FORM("
                          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="ceo\@harmani.com";
open(MAIL, "/var/qmail/bin/qmail-inject -t $to") || die
("can't open sendmail");
print MAIL "From: $FORM{'email'}\n";
print MAIL "To: $to\n";
print MAIL "Subject: $FORM submission\n\n";
print MAIL "Name: $FORM{'Name1'}\n";
print MAIl "Title: $FORM{'Title'}\n";
print MAIL "E-mail: $FORM{'Email'}\n";
print MAIL "Address: $FORM{'Address'}\n";
print MAIL "Gender: $FORM{'Gender'}\n";
print MAIL "Age: $FORM{'Age'}\n";
print MAIL "Date of Birth: $FORM{'DOB'}\n";
print MAIL "How did you find out about Harmani?: $FORM{'Info1'}\n";
print MAIL "What is it that you like about Harmani?: $FORM{'Info2'}\n";
print MAIL "What would you like to see improved at Harmani?: $FORM{'Comment'}\n";
close (MAIL);
}
sub print_thankyou_page
{
print "Content-type: text/html\n\n";
print "<HTML>\n<HEAD>\n<BODY BGCOLOR=\"#FFFF99\">\n
</HEAD>";
print "<H3>Thank you</H3>\n\n";
print "<P>\n";
print "Thank you for your submission\n";
print "<P>\n";
print "<A HREF=\"http://www.harmani.com/glance.html\";>Return</A>to the home page\n";
}
print "</BODY<\n</HTML>";


shake & bake

RE: Can anyone perl me?

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("C",hex($!))/eg;

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

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

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


I hope this helps....


 
 
 keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close