4. Hello, World, in HTML

In the previous step, you generated CGI header lines and a single plain text "content" line. In this step, you will expand the content portion and embed HTML tags within it. As a result, when the data are displayed by a Web browser, they will be formatted as conventional HTML data.

You may wish to begin with your Hello, World, from CGI script and edit it. If you do, you should change the content-type from text/plain to text/html since your program will be generating HTML.

There's really nothing to generating the HTML data. You "write" it just like you normally do for a conventional, static document, except that each line is placed inside a print statement and contains an explicit newline (\n) character, if that is desired.

Following is a Hello, World, in HTML program, set up like one of the standard pages used for course materials.

Hello, World, in HTML program

#!/usr/local/bin/perl

print "200 ok\n";
print "content-type: text/html\n\n";

print "<HTML>\n";

print "<HEAD>\n";
print "<TITLE>hello, world html </TITLE>\n";
print "<H2>Hello, World, in HTML </H2>\n";
print "</HEAD>\n";

print "<BODY>\n";
print "<HR>\n";
print "Hello, World, in HTML\n";
print "</BODY>\n";

Write your own Hello, World, in HTML program, test it, and put it in your cgi-bin directory. If you like, you can execute the program, above: Hello, World, in HTML.