Online Learning Applications for Technical English


Home
Syllabus
Assignments

Instructor



Producing Homepages

Example 1: Write a Perl CGI program to make a "Hello, world!" homepage.

We need to do the following:

  • Step 1: Write the Content-type (MIME) header for a homepage
  • Step 2: Write the HTML contents

Prepare a file as follows:

Filename: hello.cgi
#!/usr/bin/perl

#------------------------------
# [10/30/2002] - File created.
#------------------------------

#------------------------------------------------
# Step 1:  Print MIME type header for homepages.
#------------------------------------------------
  print "Content-type:  text/html\n\n";

#------------------------------------------------
# Step 2:  Print HTML contents 
#------------------------------------------------
  print "<HTML>\n";
  print "<HEAD>\n";
  print "</HEAD>\n";
  print "<BODY>\n";
  print "Hello, world!\n";
  print "</BODY>\n";
  print "</HTML>\n";

  exit;

Print a homepage


[ View result ]

To run this program, put it on your web server (be sure your Perl path in the first line is correct) and call it like a homepage:

http://sakura.cs.shinshu-u.ac.jp/cgi-bin/cai_pnk/hello.cgi

Some variations of this program:

[ Back ]