The University of Texas at Austin- What Starts Here Changes the World
Services Navigation


HTML World

The HTML World script is a slight modification of the Hello World script, helloworld.cgi. This script creates an HTML-formatted page with a black background and white text that says "Hello World!" in <H2> header text.

Open a text editor to write the script:

pico htmlworld.cgi

Type the following Perl code in your text editor exactly as it appears here:

#!/usr/local/bin/perl
# Hello World script with HTML
print "Content-type: text/html\n\n";
print '<HTML>';
print '<HEAD>';
print '<TITLE>HTML World</TITLE>';
print '</HEAD>';
print '<BODY BGCOLOR="black" TEXT="white">';
print '<H2>Hello World!</H2>';
print '</BODY>';
print '</HTML>';

Save the file and exit the editor.

Make the script executable, type:

chmod 755 $HOME/public_html/cgi-bin/htmlworld.cgi

This table includes a line-by-line explanation of htmlworld.cgi:

#!/usr/local/bin/perl Tells the server the Perl interpreter is located in the directory /usr/local/bin/perl.
# Hello World script with HTML Is a comment.
print "Content-type: text/html\n\n"; Is a print statement for the HTTP header. In this case, the header tells the Web browser to display HTML formatted text. Double quotes are required in order to create two newline characters with "\n\n".
print '<HTML>';
print '<HEAD>';
print '<TITLE>HTML World</TITLE>';
print '</HEAD>';
These print statements start the HTML document and create the <HEAD> section of the HTML page.
print '<BODY BGCOLOR="black" TEXT="white">';
print '<H2>Hello World!</H2>';
print '</BODY>';
These print statements create the <BODY> section of the HTML page with a black background and the words "Hello World!" in white <H2> text.
print '</HTML>'; This print statement closes the HTML document.

If everything ran properly, you should obtain a result similar to this one. Experiment with various colors, text, etc.


HTML World output result

 

 

 


  Updated 2006 August 14
  Comments to TeamWeb