introduction to web programming Why Perl As we've already said, CGI is not a programming language. In fact, CGI applications can be written in just about any programming language in use today.

So why exactly do most web developers choose to use the programming language Perl for their CGI applications? Could one use another language like C, C++, Apple Script or Visual Basic instead?

This is a good and extremely frequently asked question. In fact, CGI applications can be written in any programming language that is able to accept and process input, and that is able to output the results of that processing.

However, for most of the CGI applications on the web, Perl has been by far the best choice for two main reasons:

  1. Perl is the right tool for the job and
  2. Perl is easy.
Perl is the Right Tool for the Job Perl does not attempt to be a super language. In fact, compared to some more robust languages out there, Perl solves only a few, though crucial, problems.

Fortunately however, because Perl is specialized, it does the jobs it sets out to do exceptionally well. And, better yet, the limited set of problems that Perl can solve happens to fit very well with the demands of CGI.

Perl and CGI are simply a match made in heaven. Common Gateway Interface (CGI), as its name implies, provides a "gateway" between a human user with unexpected and complex needs, and a powerful, command/logic oriented server. As a gateway, CGI must perform one task very well. It must translate.

All CGI applications must translate the needs of clients into server requests, and translate server replies into meaningful and well-presented "answers". This can be quite a chore, since computers and humans typically speak very different languages.

As such, CGI must be adept at manipulating text (be it the text inputted by the client or the text received from the server). A CGI application must be able to take "strings" of data and translate them from one language to another constantly and quickly.

As it so happens, Perl has a wide variety of tools designed to manipulate strings of data. It is, in fact, one of the best languages around for string manipulation.

What's more, CGI must serve as gateway not just for one client and one server but for as many types of clients and as many types of servers as possible. It must be more than a bilingual translator, it must be multilingual, providing translation services between dozens of browser types, server types and operating systems.

Again Perl shines. Fortunately, Perl is highly portable. Due to the hard work and good intentions of many net hackers, Perl has been ported to just about every operating system you would want to run a Web server on.

Finally, Perl's weaknesses are not so negative in a web environment.

Most CGI tasks, which are ultimately at the mercy of bandwidth speed, do not demand much gusto from the application. While other compiled languages may boast ten times the power and speed or Perl, with complex functions up the yazoo, using one is like bringing in the hydrogen bomb to kill an ant. Perl is simply the right tool for the job. Other languages are typically overkill. Perl is Easy Perl is also easy to understand. Because Perl is an interpreted language, for example, there are no compilers and no illegible machine code compiled applications. What you see is what you get. The code that is run by the Web server, is the code that you see in your text editor window.

Since Perl is simple in design, it is also easy to modify, maintain and customize (which is really where the cost of software comes from anyway). That is, because Perl source code is so legible, it is very easy for one to pick up a script and quickly modify it to solve similar or new problems. Perl is a cut and paste language and program logic is easily transferred and manipulated between projects.

The benefit of this, of course, is that Perl is supported by a wide body of CGI freelance programmers. Unlike the more cryptic languages like C++ or Visual Basic, Perl is accessible to anthropology majors and computer science majors alike. In fact, newsgroups like comp.lang.perl are often too prolific to frequent on a regular basis. The Perl community is thriving and thanks to the web, expanding rapidly.

Thus, since so many people can write and modify Perl, it is very easy for you to find someone to do it for you cheaply and to do it well. You need not kneel at the mercy of the few reclusive wizards of other arcane languages who confidently slide on the curves of supply and demand. There is an abundance of qualified, starving undergraduate and graduate students with skills enough to solve most of your programming needs for very cheap rates, especially if they are given working code to modify rather than asked to write one from scratch.

Previous | Next | Table of Contents