The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
sub functions cause weird header error
Discuss sub functions cause weird header error in the Perl Programming forum on Dev Shed. sub functions cause weird header error Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 6th, 2000, 01:39 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: Washington, DC
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hey Guys, I have a problem with a perl script. When I rem out my sub proccesses it renders the output html page fine, when I run my two subproccesses it gives me the following error message:malformed header from
script. Bad header=EOT: /home/cust1/usr1216/cgi-bin/order.pl
now the sub routines call the mailto function, and each routine sends its email message fine. I think the problem may be how long these sub routines take to fire. Is there anyway I can get my perl script to call these subs and then not wait for them to complete while writing the rest of the web page? Does anyone have an Idea on this?
|

July 6th, 2000, 09:49 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>malformed header from script. Bad header
You need this line -> print "Content-type: text/htmlnn";
>>I think the problem may be how long these sub routines take to fire.
No.
|

July 7th, 2000, 08:42 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: Washington, DC
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Nah I already have that bit with
the print "Content-type: text/htmlnn";
This does bring up the interesting question though, how many new lines can occur
after that without any html or text being
presented.
To clarify here's sort of whats going on in the perl script:
an If statement that decides which html document to print.
first line after the if and after the else (and no they can never both fire) is the
print "Content-type: text/htmlnn";
line. The problem is that in the if statement after I call that If I call my two subs that send mail and then try to print out the web page I get the malformed header problem. If I rem out these two subs the page prints fine. I looked very hard at the mailto subs and the only thing I could think of is that they are sending some sort of "close header" response upon sending a message. I don't really know. Any help here would be greatly apreciated!!!
-nate
|

July 7th, 2000, 10:19 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
I always just creat a header sub routine and call it before html output.
|

July 7th, 2000, 10:28 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: Washington, DC
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
That sounds like a good idea, would you
mind posting your subroutine? I'm still getting the hang of this perl thing. =)
(do you fork the proccess or what?)
|

July 7th, 2000, 11:58 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>The problem is that in the if statement after I call that If I call my two subs
Try not to do this:
if (blah blah) {
many lines here
}
else {
many other lines here
}
In some situations, you can also put this line about the if else block ->
print "Content-type: text/htmlnn";
>>send mail and then try to print out the web page I get the malformed header problem.
You probably left out print "Content-type: text/htmlnn"; somewhere.
If your script is less than 100 lines long, please post it here so we can do some cleanup and bugfix for you.
|

July 7th, 2000, 12:54 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Yes, please post the code... I'd be interested in seeing it.
As for the sub routine, here ya go:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
sub header {
print "Content-type: text/htmlnn";
}
[/code]
Then to call it just type:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
&header;
[/code]
You can put the sub routine at the bottom of your perl script (in fact that what the standard is). It doesn't have to come before you call it.
|

July 7th, 2000, 02:24 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: Washington, DC
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
okay here is about 100 lines of the script. This bit doesn't include the sub routines, I can include those in a followup message if there is interest... -nate
if ($cname && $card && $cnum && $cexm && $cexy)
{
print "Set-Cookie: ShopCart=$cart; path=/; expires=Monday, 7-Apr-01 20:00:00 GMT; secure;n";
print "Content-type: text/html nn";
#Read In User Information From ID File
open(ID,$userdir.$id) | | die "!ERROR: Open $id File FAILED";
@idfile=<ID>;
close(ID);
@sinfo= split (/|/, $idfile[0]);
$dd = `date`;
$name=$sinfo[0];
$address=$sinfo[1];
$city=$sinfo[2];
$state=$sinfo[3];
$zip=$sinfo[4];
$country=$sinfo[5];
$email=$sinfo[6];
$phone=$sinfo[7];
#print "<BR>$name<BR>$userdir.$id<BR>$sinfo[0]<BR>";
$intnum = int ($total);
$pointadd = $intnum * 10;
$sinfo[9] += $pointadd;
open(ID, "> ".$userdir.$id) | | die "!Cookie,!Form: Error Opening ID File";
print ID "$sinfo[0]|$sinfo[1]|$sinfo[2]|$sinfo[3]|$sinfo[4]|$sinfo[5]|$sinfo[6]|$sinfo[7]|$sinfo[8]|$sinfo[9]n";
close (ID);
chmod (0666, $userdir.$id);
print <<SHANK;
<HTML>
<TITLE>Black Belt Order Confirmation</TITLE>
<BODY background="/gifs/back.gif" link=#fa7700 vlink=#aa99ff>
<table>
<tr>
<td width=160 valign=top>
SHANK
open(IN,"/home/cust1/usr1216/html/navigation.txt");
@navigation=<IN>;
close(IN);
print @navigation;
print <<SHANK;
</td>
<td width=530 valign=top>
<CENTER>
<font face=arial><B>
Thank you for ordering from Black Belt.
<br>
You should recieve an email receipt shortly.
</B></font>
</CENTER>
</td>
</tr>
</table>
</BODY>
</HTML>
SHANK
# This really shouldn't be down here, but do to weird parsing error with headers it is shoved down here, learn more perl and fix.
$SIG{&do_mail} = sub { wait };
$SIG{&do_receipt} = sub { wait };
}
else {
calc_prices();
print "Content-Type: text/htmlnn";
print <<POON;
<HTML><HEAD><TITLE>Black Belt Ordering Credit Card Information</TITLE></HEAD>
<BODY background="/gifs/back.gif" link=#fa7700 vlink=#aa99ff>
<table>
<tr>
<td width=160 valign=top>
POON
open(NAV,"/home/cust1/usr1216/html/navigation.txt");
@navigation=<NAV>;
close(NAV);
print @navigation;
print <<POON;
|

July 7th, 2000, 02:29 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: Washington, DC
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
errr I forgot to put the two subroutines back at the top where I had them. They originally followed the following two lines:
print "Set-Cookie: ShopCart=$cart; path=/; expires=Monday, 7-Apr-01 20:00:00 GMT; secure;n";
print "Content-type: text/html nn";
|

July 7th, 2000, 07:51 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>$intnum = int ($total);
>>$pointadd = $intnum * 10;
$intum and $total have no references at all.
>>open(ID, "> ".$userdir.$id) | | die "!Cookie,!Form: Error Opening ID File";
What are you trying to do with it? It's an existing file and you want to write a new line?
open(ID,">>$userdir.$id");
#############################################
open(IN,"/home/cust1/usr1216/html/navigation.txt");
@navigation=<IN>;
close(IN);
#############################################
I would put these within this two lines on top:
print "Content-type: text/html nn";
#Read In User Information From ID File
If open(IN,"/home/cust1/usr1216/html/navigation.txt"); fails, you probably wanna send an error message and exit since this is independent.
You can always -> print "@navigationn"; later down the bottom.
chmod (0666, $userdir.$id);
#Your sendmail subroutine should go here
#it could look as simple as &do_mail;
print <<SHANK;
You really need to cleanup/separate your codes and try not to mix html and your perl together.
|

July 10th, 2000, 02:28 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: Washington, DC
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
thanks for all the help guys! I think
i've got it working a bit more efficiently.
I didn't originally write the code (dodge responsibility for bad code) I'm actually just porting it over from one system to another and trying to modernize it a little. (though I don't really know perl all that well yet) Anyhow, all of your posts helped me a lot. =)
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|