Wicked Cool Perl Scripts | WebReference

Wicked Cool Perl Scripts


[next]

Wicked Cool Perl Scripts

Cover: Wicked Cool Perl Scripts
This chapter is excerpted from the book, Wicked Cool Perl Scripts, 2nd Edition, authored by Steve Oualline. Copyright 2006 No Starch Press, February 2006.


CGI Debugging

Perl and the Web were made for each other. The Perl language is ideal for processing text in an environment where speed does not matter. Perl can munch text and use it to produce dynamic web pages with ease.

But programming in a CGI environment is not the easiest thing in the world. There is no built-in CGI debugger. Also, error messages and other information can easily get lost or misplaced. In short, if your program is not perfect, things can get a little weird.

In this chapter, I'll show you some of the Perl hacks you can use to help debug your CGI programs.

Hello World

This is the CGI version of "Hello World." In spite of it being a very simple program, it is extremely useful. Why? Because if you can run it, you know that your server is properly configured to run CGI programs. And from bitter experience I can tell you that sometimes configuring the server is half the battle.

The Code

Running the Script

To run the script, just point your web browser at the correct URL. If you are using the default Apache configuration, the script resides in ~apache/cgi-bin/hello.pl and the URL to run it is http://server/cgi-bin/hello.pl.

The Results

The results

How It Works

The script just writes out its greeting, so the script itself is very simple.

The purpose of the script is to help you identify all the problems outside the script that can prevent CGI scripts from running.

Hacking the Script

In this section, I'm supposed to tell you how to enhance the script. But really, what can you do with "Hello World!"?

I suppose you could enhance it by saying "Hello Solar System," "Hello Galaxy," or "Hello Universe." You are limited only by your imagination.


[next]

URL: