Debugging an Application

This case study is a bit different from the others, since it doesn't explain a particular application, rather than the development of an application. The application is a rather simple one: tell the user what host the web server believes made the HTTP request and display it using a chtml template. We will use Perl for this example, but many of the same concepts apply in other languages.

You can also view information about common error messages you may see either during script development or even after the script is in production use.

This case study will show several versions of the same script, and enable you to actually try the buggy scripts to see what the output will look like. For each link which executes a script, you will see a small section at the top which explains the output and lets you proceed. If you are not on a browser which supports embedded HTML objects, you will need to use the browser back button after trying the test scripts to find a link to the next page.

Here is the template which we will use:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<!--chtml include "//webinfo/incs/"-->
<html xmlns="">
<title>Client Hostname</title>
<link rel="stylesheet" href="/webinfo/webinfo.css" type="text/css" />

<h1>Client Hostname</h1>
<!--chtml include "//webinfo/incs/"--> 
You are coming from the host REMOTE.
<!--chtml include "//webinfo/incs/"-->

And this is our first attempt at the script:


use strict;
use CGI;
require '/www/lib/';

$cgi = new CGI;

$file = chtml_procfile ('client.tmpl');
if (! open F, '<$file')
    exit 0;

while (<F>) {
close F;

Before starting, be warned that throughout this documentation we will call the name of the script "client.cgi". However, in order to be able to try different versions, the actual scripts are "client1.cgi", "client2.cgi", etc. This subtlety is important when you view the error messages.

Let's see what happens when we try to access the script.