While almost any language can be used for CGI,
Perl is the one most widely used. It has the following advantages:
- The use of here documents which greatly
ease the problem of writing HTML and.or JavaScript programs from
within the CGI program. Often the main purpose of a CGI program is to
create HTML and/or JavaScript code which is sent back to the client
for subsequent execution there. This happens so frequently that any
formatting tools which reduce this problem are very important.
- Access to server environmental variables, files, and
processes:
Perl lets you access many environmental variables, through the $ENV{}
array, such as the PATH, HOME, or SHELL. You can invoke any
Unix system command or user program through the "system()" routine, or
within "backticks",
such as `user/ucb/finger`, or through pipes which are treated like files,
and can read/write or get information about files.
- Perl contains very powerful string matching and substituting
expressions (called "regular expressions") which are ideal for scanning
files to locate or change
information. For example,
/at(.)d*(c+)/
locates any string that starts with "at" followed by any single
character followed by 0 or more "d's", followed by one or more "c's". It
also stores whatever character it found after "at" in a variable named
"$1", and the string of 1 or more "c's" is stored in $2.