Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 6th, 2000, 01:39 PM
mistcat mistcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Washington, DC
Posts: 12 mistcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old July 6th, 2000, 09:49 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.

Reply With Quote
  #3  
Old July 7th, 2000, 08:42 AM
mistcat mistcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Washington, DC
Posts: 12 mistcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old July 7th, 2000, 10:19 AM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I always just creat a header sub routine and call it before html output.

Reply With Quote
  #5  
Old July 7th, 2000, 10:28 AM
mistcat mistcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Washington, DC
Posts: 12 mistcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?)

Reply With Quote
  #6  
Old July 7th, 2000, 11:58 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.

Reply With Quote
  #7  
Old July 7th, 2000, 12:54 PM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.

Reply With Quote
  #8  
Old July 7th, 2000, 02:24 PM
mistcat mistcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Washington, DC
Posts: 12 mistcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;

Reply With Quote
  #9  
Old July 7th, 2000, 02:29 PM
mistcat mistcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Washington, DC
Posts: 12 mistcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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";

Reply With Quote
  #10  
Old July 7th, 2000, 07:51 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.



Reply With Quote
  #11  
Old July 10th, 2000, 02:28 PM
mistcat mistcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Washington, DC
Posts: 12 mistcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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. =)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > sub functions cause weird header error

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap