View Full Version : Perl problems....
TheMatrix
February 11th, 2011, 07:48 PM
So, Whenever I try to write a script in perl and run it, I get an error:
It says:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: hello.cgi
If you think this is a server error, please contact the webmaster.
Error 500
127.0.0.1
Fri 11 Feb 2011 04:43:52 PM PST
Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
Here is the code for that script:
#!/opt/lampp/bin/perl -wT
print "Content-type: text/html\n\n";
print "Hello, world!\n";
exit;
I don't see the problem with that. Does anyone else?
Thanx
PJay
February 11th, 2011, 08:09 PM
Check the Apache logs (eg /var/log/httpd/error_log) which might give you a clue. I can't see anything wrong with your code so it might be permissions on the script itself (eg its not in a folder Apache thinks it can execute from).
nick
February 12th, 2011, 04:09 AM
Any particular reason for using perl? Its a foul language, php is much better.
PJay
February 12th, 2011, 06:20 AM
Any particular reason for using perl? Its a foul language, php is much better.
Yeah PHP would be easier and better for general web coding, but Perl is an awesome language for 'system stuff' and things like playing with text logs etc. So if your web pages are basically a front end to stuff you are doing with the system itself Perl will be a better way imho.
But if I'm right this is down to Apache not having run permissions on this file or whatever then you could have the same problem if this was a PHP script.
TheMatrix
February 16th, 2011, 08:58 PM
Check the Apache logs (eg /var/log/httpd/error_log) which might give you a clue. I can't see anything wrong with your code so it might be permissions on the script itself (eg its not in a folder Apache thinks it can execute from).That directory doesn't exist. I'm using LAMPP, btw.
Any particular reason for using perl? Its a foul language, php is much better.Not really - it's just that the perl syntax just makes more sense to me, personally.:P
Anyways, the original script works, but this one doesn't:
#!/opt/lampp/bin/perl -wT
#CGI.pm test script
use strict;
use CGI;
my $q = new CGI;
print $q->start_html("HTML test");
$q->h1("HTML Test");
$q->hr;
$q->p("HTML test!!");
$q->hr;
$q->end_html;
exit;
I have CGI.pm installed, and perl is version 2.0.4
PJay
February 17th, 2011, 03:47 PM
Anyways, the original script works, but this one doesn't:
#!/opt/lampp/bin/perl -wT
#CGI.pm test script
use strict;
use CGI;
my $q = new CGI;
print $q->start_html("HTML test");
$q->h1("HTML Test");
$q->hr;
$q->p("HTML test!!");
$q->hr;
$q->end_html;
exit;
I have CGI.pm installed, and perl is version 2.0.4
I think you just need to "print" each line, or output it as a preformatted block, which if i remember correctly is
print <<UPTOHERE;
stuff to print
asdflksjjdflksjflsdjfsdf
more stufff to print
UPTOHERE
P.
TheMatrix
February 18th, 2011, 12:01 AM
I think you just need to "print" each line, or output it as a preformatted block, which if i remember correctly is
print <<UPTOHERE;
stuff to print
asdflksjjdflksjflsdjfsdf
more stufff to print
UPTOHERE
P.
Actually, no. There is something in CGI.pm that dosen't require that. It's called "Generating output with CGI.pm" or something like that.
I think there's something wrong with the headers.
PJay
February 18th, 2011, 02:27 PM
Oh I see (I think) ... so why do you have a print for that one line? Cos wont that print just try to evaluate the following statement as an expression.. and just send the resulting true / false or whatever to the page? Maybe its not setting the start_html value because of that?
I'd try removing the print and see if it works.
darkwoon
February 18th, 2011, 05:04 PM
That directory doesn't exist. I'm using LAMPP, btw.
Not really - it's just that the perl syntax just makes more sense to me, personally.:P
Anyways, the original script works, but this one doesn't:
#!/opt/lampp/bin/perl -wT
#CGI.pm test script
use strict;
use CGI;
my $q = new CGI;
print $q->start_html("HTML test");
$q->h1("HTML Test");
$q->hr;
$q->p("HTML test!!");
$q->hr;
$q->end_html;
exit;
I have CGI.pm installed, and perl is version 2.0.4
That's because you are only printing the start_html part, and not the following lines. Replace the ";" by concatenation dots:
print $q->start_html("HTML test") .
$q->h1("HTML Test") .
$q->hr .
$q->p("HTML test!!") .
$q->hr .
$q->end_html;
That should work a little better ;)
PJay
February 18th, 2011, 05:27 PM
That's because you are only printing the start_html part, and not the following lines. Replace the ";" by concatenation dots:
print $q->start_html("HTML test") .
$q->h1("HTML Test") .
$q->hr .
$q->p("HTML test!!") .
$q->hr .
$q->end_html;
That should work a little better ;)
Surely thats just the same a block print though?
darkwoon
February 18th, 2011, 05:41 PM
Surely thats just the same a block print though?
Not quite, as in this case you're relying on the methods of the CGI object; with a print block, unless I'm mistaken, you're merely sending stuff to stdout.
PJay
February 18th, 2011, 06:04 PM
Not quite, as in this case you're relying on the methods of the CGI object; with a print block, unless I'm mistaken, you're merely sending stuff to stdout.
Variable interpolation is done on a print block so its the same deal for the CGI methods I think but I'd have to try it to be sure ;-)
darkwoon
February 18th, 2011, 06:15 PM
Variable interpolation is done on a print block so its the same deal for the CGI methods I think but I'd have to try it to be sure ;-)
True, but there is more than variable interpolation - the CGI object can tweak the text stream in other ways (maybe it properly escapes special chars for html compliance, for example, though I don't know if it really does that).
TheMatrix
February 18th, 2011, 08:24 PM
Oops.....
It turns out that that there were incorrect permissions on the scripts, even though I did do:
chmod 777 -R cgi-bin/
Odd......
Oh well - it works now. Case closed ;)
Thanks everybody :)
vBulletin® v3.8.9, Copyright ©2000-2021, vBulletin Solutions, Inc.