Defining PERL and CGI Scripts

PERL which is referred to as Practical Extraction and Reporting Language, is a high level programming language and can be used to perform a widespread variety of tasks. Perl was developed originally by Larry Wall in 1987 and since then has undertaken several revisions. It gained popularity in the late 1990s as a CGI scripting language. Today, Perl is used for network programming; graphics programming; bioinformatics, and system administration and for other applications.

A traditional use of Perl would be for taking information from a text file and converting it into another form. Perl also can be used for systems programming and the programs which are written using Perl are called Perl scripts. The implementation of Perl is as an interpreted language as opposed to a compiled one. This is the reason why the execution of a Perl script uses more of CPU time.

CGI on the other hand stands for Common Gateway Interface. It is a standard programming interface used between external programs and web servers. CGI interacts with numerous operating systems; provides users to have access to many programs and uses a distinct method in interacting with a web server. Today, in programming websites, CGI has been the most mature tool of providing dynamic web content. With the emergence of server –side programs like ASP, PHP, Java servlets and ColdFusion, CGI has held its ground and it still the most pervasive server-side technology.

CGI Programming in Perl

CGI allows web users to relay information to programs written in any language. Using an interpreted language like Perl in CGI applications has the advantage in its simplicity in development, revision and debugging. Not having to consider compilation, you can take away the hassle that goes with debugging compiled programs. Not all interpreted language is up to the task but Perl has the unique edge in that it has an exceptionally capable functionality.

Perl was developed over a decade ago for text processing but has now since become a powerhouse object-oriented language. With Perl’s text manipulation features and CGI.pm module, Perl gives an object-oriented interface to mostly all CGI-related tasks. While there may be other languages that are more efficient, Perl is still considered to be the de facto language for CGI.

However, there are times when you have to use C or other compiled language for more mature CGI applications. Usually, these are web application where speed is very crucial. If you would want to have a very active website, perhaps you should want to use a compiled language.

Writing and Running CGI Scripts

CGI scripts exist in many forms which depend upon what the server supports. As commonly known, CGI scripts are written using any of the following:

  • Perl Scripts
  • C/C++ programs
  • Unix Scripts

As mentioned previously, Perl is the widely used script for CGI and we will be focusing on this. When running CGI, it can be done in a variety of ways. Two of the most common ways are as follows:

  • Direct URL Reference
  • From an HTML form

Before running the script you have to bear in mind that scripts needs to be run in the correct directory. Also check if the script has proper file extension and shebang line. Then, permissions need to be set correctly. Run your script at the command line to test for syntax errors.

Why use Perl for CGI?

Below are some of the reasons why Perl is commonly used for CGI:

  • Flexible text handling
  • Socket support
  • Pattern matching

The major advantage of using an interpreted language rather than a compiled one in CGI applications is its simplicity.