HOW TO: Write a basic CGI Script for testing?

Here is an example of what is probably the most basic CGI Script in perl:

#!/usr/bin/perl
# It's always a good idea to use the strict pragma while developing
# Perl code, it makes Perl warn about dangerous code
use strict;

# We're also going to include the CGI module, so that we can take
# advantage of other programmer's efforts (One of Larry Wall's basic
# tennants is that programmers are fundamentally lazy -- he's probably
# right, but I can't be bothered to prove it right now)
use CGI;

# instantiate a new CGI object
my $cgi = new CGI;

# perform a single print statement, with liberal use of the perl
# string concatenator "." and some CGI methods
print
   $cgi->header .
   $cgi->start_html('Hello World!') .
   $cgi->h1('Hello World!') .
   $cgi->end_html;

# Tell the webserver everything is fine
exit (0);

#!/usr/bin/perl
# It's always a good idea to use the strict pragma while developing
# Perl code, it makes Perl warn about dangerous code
use strict;

# We're also going to include the CGI module, so that we can take
# advantage of other programmer's efforts (One of Larry Wall's basic
# tennants is that programmers are fundamentally lazy -- he's probably
# right, but I can't be bothered to prove it right now)
use CGI;

# instantiate a new CGI object
my $cgi = new CGI;

# perform a single print statement, with liberal use of the perl
# string concatenator "." and some CGI methods
print
   $cgi->header .
   $cgi->start_html('Hello World!') .
   $cgi->h1('Hello World!') .
   $cgi->end_html;

# Tell the webserver everything is fine
exit (0);

To test that Perl and CGI Scripts are working, save the text above in a file called hello.cgi. Then upload the above file to the server.

http://yourdomainname/www/hello.pl

(Replace 'yourdomainname' with your actual domainname.)

You should be able to access the CGI Script URL:

http://yourdomainname/hello.pl

(Replace yourdomainname with your actual domain name.)

and you should see the output:

Hello World!

 

  • Email, SSL
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

What is the difference between shared SSL and private SSL?

A shared SSL displays as https://ip/~yourusername/. A private SSL would display as...

Why are my FrontPage extensions not working?

You must first make sure you have installed the extensions from going into your cpanel and...

Application Paths

Here are the applications paths. If you do not see what you are looking for, please email...

Custom error pages

To create a custom error page for your account you will need to upload a file with the...

How do I use SSL to setup my email?

Set your mail server to the host name for SMTP/POP3/IMAP (instead of domain.com) and then make...