Checking for Common Errors

The first thing to do is to make sure the script is executable.

% ls -l client.cgi
-rw-rw-r--  1 username      254 Apr  5 14:03 client.cgi
% chmod +x client.cgi
% ls -l client.cgi
-rwxrwxr-x  1 username      254 Apr  5 14:03 client.cgi*

While we're at it, we should do a syntax check on the script:

% perl5 -cw client.cgi
Scalar found where operator expected at client.cgi line 7, at end of line
        (Missing semicolon on previous line?)
syntax error at client.cgi line 7, near "$cgi "
Global symbol "cgi" requires explicit package name at client.cgi line 7.
Global symbol "file" requires explicit package name at client.cgi line 9.
syntax error at client.cgi line 11, near ")
    exit"
client.cgi had compilation errors.

The first order of business is to add a semicolon to the end of the require line.

Since we have the use strict; declaration at the top of the script, Perl will require that we not use variables before they are declared. We can accomplish this by changing the expressions on line 7 and line 9 to also be variable declarations:

my $cgi = new CGI;

my $file = chtml_procfile ('client.tmpl');

As for the syntax error, we see that lines near the error are the if statement:

if (! open F, '<$file')
    exit 0;

Perl requires that all if statements have the conditional code be in braces. We change these lines to be:

if (! open F, '<$file') {
    exit 0;
}

Doing one more check shows:

% perl5 -cw client.cgi
client.cgi syntax OK

We are now ready to try the script again.