Web Hosting Talk







View Full Version : Perl "Here" document not working...?


jasonfahy
03-21-2005, 04:26 AM
Are "here" documents in Perl universally supported?

Mine keep causing Error 500s and I can't figure out why.

Here's the code I was trying to run:


#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

print <<"Hypertext";

<HTML>
<HEAD>
<TITLE>The 29th Armored Regiment</TITLE>

<LINK REL="stylesheet" TYPE="text/css" HREF="http://www.29tharmor.com/mainstyle.css">

</HEAD>
<BODY>
<H1>
Record a New Shoot</H1>
</BODY>
</HTML>

Hypertext


Even with the script trimmed down to here, I was getting 500 Errors. Any idea what could be going wrong? The code works perfectly if I stuff each line into an individual print statement with backslashes in front of the quotes, but that is, of course, a gigantic pain.

Thanks for any suggestions.
J

sitekeeper
03-21-2005, 05:14 AM
There is nothing wrong in your code.... did you chmod it 755?

jasonfahy
03-21-2005, 12:04 PM
I often make that mistake (iPower has this idiotic feature that keeps resetting .cgi files to 644) but I've checked this one many times - it's 755.

I've also quadruple-checked the URLs, and they're correct; I've used the same structure in other scripts and it's worked ok.

I Googled this and found something that (if I understood right) indicated you can't end a script with the closing tag of a "here" document. I don't see why it would be that way, but with my six days of Perl experience I'm not about to argue; I'll try that today at lunch and let you know what happens.

Donboy
03-21-2005, 12:32 PM
This could be a CR/LF problem. Windows uses CR... Unix uses LF. If you're composing your script under Windows, you need to change the formatting to LF before you upload. Could this be your problem?

jasonfahy
03-21-2005, 01:19 PM
(I assume those mean carriage return and linefeed...)

Um, it's certainly possible. This file has been worked on using the vDeck online file editor, Notepad and Wordpad, and I've cut-and-pasted back and forth between them several times during the debugging process. From the ____pad programs I always save as plain text.

How can I view the file so that I see the end-of-line characters? Open it in Word with Show Formatting on? :confused:

AymanH
03-21-2005, 01:33 PM
Some editors, like EditPlus, have a feature to save text files in Unix format, you can also use FTP and transfer the file in text mode.

jasonfahy
03-21-2005, 04:33 PM
Yes, it appears that Notepad and Wordpad are equally incompetent at saving text; they both use bytecodes at the ends of lines which aren't Unix-compatible.

Future generations may find this link helpful:

http://michaelbluejay.com/webdesign/perl.html

cliveholloway
03-23-2005, 03:11 PM
Jason,

You have turned on Apache error logging in Reports -> Logs -> Error , yes? Then you can look at the actual error to see why Apache's baulking.

Also, adding this line to the beginning of your script will echo most errors in the browser:

use CGI::Carp 'fatalsToBrowser';

(remove it when your down as a minor security lockdown)

I guess you worked the problem out - since the scripts appear fine now.

You might also want to look at using CGI.pm to save yourself some typing :) Eg,

print scrolling_list('callsign',\@gunnerdata);

The docs are here (http://stein.cshl.org/WWW/CGI/#checkbox) , but you might find Ovid's CGI course (http://users.easystreet.com/ovid/cgi_course/) or articles on Perlmonks (http://perlmonks.org) more accessible.

cLive ;-)

jasonfahy
03-23-2005, 03:44 PM
You, sir, are on my Christmas card list. :) I'm going to try that immediately...

jasonfahy
03-23-2005, 05:20 PM
fatalsToBrowser is the new sliced bread. :gthumb:

I checked out Perlmonks, and it looks like it's full of good general information. It also looks like a typical Perl programmer would kill his own children if they failed to use CGI.pm, so until/unless I figure out how to use that module for forms management, I'll be keeping my head down in the forum... ;)

More info for future generations: Perl has some kind of hangup with a "here" document's closing tag being the last thing in the script, so finishing up with

print <<"Hypertext";

<HTML>
<BODY>
Woo hoo, I'm done!
</BODY>
</HTML>

Hypertext


is no good. I threw in a final line that just says

exit;

and suddenly the problem went away.

cliveholloway
03-25-2005, 04:41 PM
Originally posted by jasonfahy
More info for future generations: Perl has some kind of hangup with a "here" document's closing tag being the last thing in the script, so finishing up with

The here document needs to be terminated with a new line. That's all. :)

cLive ;-)