#!/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?
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!