tags:

views:

205

answers:

3

I have written following in index.pl which is the C:\xampp\htdocs\perl folder:

#!/usr/bin/perl
print "<html>";
print "<h2>PERL IT!</h2>";
print "this is some text that should get displyed in browser";
print "</html>";

When I browse to http://localhost:88/perl/ the above HTML doesn't get displayed (I have tried in IE FF and chrome).

What would be the reason?

I have xampp and apache2.2 installed on this Windows XP system.

A: 

I am just guessing.

  • Have you started the apache server?
  • Is 88 the correct port for reaching your apache?

You may also try http://localhost:88/perl/index.pl (so adding the script name to the correct address).

Check this documentation for help.

rics
@rics thanks for reply ,apache is on (started)when i run this ,also 88 is right port cause other project i created in php works just fine
dexter
@rics Please don't guess.
Sinan Ünür
+2  A: 

Maybe it's because you didn't put your text between <body> tags. Also you have to specify the content type as text/html.

Try this:

print "Content-type: text/html\n\n"; 
print "<html>";
print "<h2>PERL IT!</h2>";
print "<body>";
print "this is some text that should get displyed in browser";
print "</body>";
print "</html>";

Also, from the link rics gave,

Perl:
Executable: \xampp\htdocs and \xampp\cgi-bin
Allowed endings: .pl

so you should be accessing your script like: http://localhost/cgi-bin/index.pl

ccheneson
@ccheneson : thanks!!.. its because of content type
dexter
cool, well if it works, I ll remove my comment on the port.
ccheneson
@ccheneson : the edited code you gave how to use it? Perl:Executable: \xampp\htdocs and \xampp\cgi-binAllowed endings: .pl
dexter
The above means that your html should go under htdocs and all perl scripts should be place under cgi-bin folder
ccheneson
+3  A: 

See also How do I troubleshoot my Perl CGI Script?.

Your problem was due to the fact that your script did not send the appropriate headers.

A valid HTTP response consists of two sections: Headers and body.

You should make sure that you use a proper CGI processing module. CGI.pm is the de facto standard. However, it has a lot of historical baggage and CGI::Simple provides a cleaner alternative.

Using one of those modules, your script would have been:

#!/usr/bin/perl
use strict; use warnings;
use CGI::Simple;

my $cgi = CGI::Simple->new;

print $cgi->header, <<HTML;
<!DOCTYPE HTML>
<html>
<head><title>Test</title></head>
<body>
<h1>Perl CGI Script</h1>
<p>this is some text that should get displyed in browser</p>
</body>
</html>
HTML

Keep in mind that print has no problem with multiple arguments. There is no reason to learn to program like it's 1999.

Sinan Ünür