2
#!/usr/local/bin/perl
use warnings;
use strict;

print "Hello, world!\n";

This is the file I have saved as test.pl in cgi-bin.

And this is the code and I'm using to run the script in a separate html document

 <html> 
 <head> 
 <title>A Very Basic Example of an HTML page created by the CGI</title> 
 </head> 
 <body> 
 <script type="text/javascript" src="http://csvlife.com/cgi-bin/test.pl"></script> 
 </body> 
 </html>

I installed Perl. modules. I verified the program path in my Hostgator panel. What might be the problem?

2
  • 6
    The perl script does not output valid java script code. Commented Dec 14, 2012 at 10:14
  • 1
    Script by URL works for me. You're not executing it on the page. You just included it as a javascript resource. Commented Dec 14, 2012 at 10:15

1 Answer 1

7

Perl scripts, unlike Javascript, are executed on the server side. This means you run a Perl script by pointing your browser to the script directly, not embedding the script in an HTML page.

It is considered good practice to use a module to handle CGI. The classic option is simply called CGI. A hello world example using this module is found here.

Quentin also mentioned Plack as another alternative. I haven't used this, but it looks like a much more powerful solution. It might be a bit much for a beginner, though.

These Perlmonks tutorials are a good resource for CGI programming. Caveat: they are mostly pretty old. Check the documentation to ensure that you are doing things in the most up to date way.

Have fun, and feel free to ask more questions if you need help!

Sign up to request clarification or add additional context in comments.

4 Comments

Generally speaking, Plack is a nicer option than CGI (and is compatible with CGI). CGI.pm is a bit easier to get running (especially on cheap hosting) and is still better then trying to craft CGI by hand.
@Quentin, thanks for the suggestion. I added it to the answer.
So let me get this straight. If I have a perl script in the bin folder its automatically running on the server without calling it?
@DieVers No, the script gets run on the server whenever it is requested by a client. The client doesn't receive the contents of the script, but the output. However, some technologies have the script always running in the background, to avoid startup costs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.