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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Works with print statements but not without! Why?

Status
Not open for further replies.

marybailey

Programmer
Mar 14, 2002
47
US
Okay. This code works. It changes my file and runs fine.
But (and its a BIG but) when I take the prints out it gives me a 500 error. I want to take this piece of code and use it without the prints.
Help!
Mrs B.

-------------------------------------------------------
#!/usr/local/bin/perl

print "Content-type: text/html\n\n";
print &quot;<HTML>\n&quot;;
print &quot;<BODY BGCOLOR=#FFFFFF>\n&quot;;
print &quot;<CENTER>\n&quot;;

$data_file=&quot;../text/joinlist.txt&quot;;

open(DAT, $data_file) || die(&quot;Could not open file!&quot;);
@raw_data=<DAT>;
close(DAT);

$i=0;
foreach $member (@raw_data)
{
chop($member);


($mactive,$mrealname,$memail,$mmonth1,$mday1,$mmonth2,$mday2,$mmonth3,$mday3,$mmonth4,$mday4,$mspec

ial,$mhow)=split(/\,/,$member);

if ($mactive == 5) {
$mactive = 1;}

$hold=&quot;$mactive,$mrealname,$memail,$mmonth1,$mday1,$mmonth2,$mday2,$mmonth3,$mday3,$mmonth4,$mday4,

$mspecial,$mhow&quot;;
$tempArr[$i] = $hold;
$i=$i+1;
}

open(DAT,&quot;>../text/joinlist.txt&quot;) || die(&quot;Could not open file!&quot;);
foreach $gal (@tempArr)
{
print DAT &quot;$gal\n&quot;;
}
close(DAT);


print &quot;</CENTER>\n&quot;;
print &quot;</BODY></HTML>&quot;;
 
To clarify, its only when i remove the html prints not the print to the file.
(HOw do I remove the duplicate post?)
Mrs B
 
The 'getting a 500' error implies that you are trying to run this page from an http request. The web server expects to create and return to the requesting machine/browser a compliant http header (maybe followed by some html). If you remove the 'print &quot;Content-type: text/html\n\n;&quot; line, then the web server never returns a compliant header. The web server is smart
enough to realize this and it lets you know via the 500 error. If you want this to run as a CGI, you'll have to contrive some mechanism to make the web server think all is well.

What exactly are you trying to do?
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
So how do I do this? This cgi ultimately is called to handle an html form.
Mrs B
 
oh yeh, I red-flagged the duplicate post. TTs management should clean it out shortly. ;-)

Anyone can red-flag any post via the like at the bottom of each entry. TTs management reviews the red flag and post and takes appropriate action. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Firstly, try turning on warnings with the -w switch:
[tt]
#!/usr/local/bin/perl -w
[/tt]
as you should then get more descriptive error messages in your error log. If the script has to output data to the web then you will need to print:
[tt]
print &quot;Content-type: text/html\n\n&quot;;
[/tt]
or:
[tt]
print &quot;Content-type: text/plain\n\n&quot;;
[/tt]

before any other output or you will get an internal server error. There is no way that I know of to get around this. You should be able to take out all of the other print statements except this one.

Will.
fortytwo
will@hellacool.co.uk
 
When you say any other output do you mean to include output written to a file?
Jean
 
I still don't understand the flow you are trying to achieve.

Do you have a user that is submitting a form to the CGI?

If so, then why not send them a confirmation page, or redirect them to another url?

If there is no user submitting a form, and you just want a mechanism to trigger the cgi, then you could the the LWP module,
Code:
use LWP::Simple;
$url = '[URL unfurl="true"]http://www.yourserver.com/your_cgi.cgi';[/URL]
$content = get($url);
print &quot;Content-type: text/html\n\n&quot;;
print &quot;$content&quot;;

As above, I'm still not clear on what you're trying to do.
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I meant output to the browser, should have been more specific :). When you call a cgi the webserver will expect an output. This is independent of file input and outputs in the script. If you don't have a:
[tt]
print &quot;Content-type: text/html\n\n&quot;;
[/tt]
somewhere in your script you will get an error if it was called as a CGI, ie. in a web browser from a web server.

Will.
fortytwo
will@hellacool.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top