CGI Scripts
Language Choice
CGI Caveats |
Language Choice |
CGI and Forms
The warnings of the previous section were meant to discourage
the faint of heart. We certainly did not mean to imply that
writing and implementing CGI scripts are beyond ordinary
mortals, only that they are beyond the average difficulty
level of the present Tutorial. For those who may want to
go further, we provide some additional information that
will get you started in the right direction.
What Languages Are Used
for CGI Scripts?
If you decide that you wish to implement CGI scripts of
your own creation, you then need to decide which language
you will want to use for writing the scripts. In principle,
you can use any language that allows you to create executable
code on the server to accomplish the required task. The
earlier example that returned the current date and time
used what is called a Unix shell script, which
is a rather simple scripting language available on Unix
servers (If you are interested, here is a
listing of the shell script that returned the date.)
In practice, the server software on some platforms may
limit you in your choice of languages. For instance, the
MacHTTP Web server for the Macintosh will only execute programs
written in the Mac's proprietary scripting language called
AppleScript.
Perl and C
At present two of the most commonly used languages for
writing gateway programs (especially on Unix systems, which
are the most common servers on the Web) are C and Perl (which
then allows you to write "Perly gateway scripts"!). Both
of these languages are quite powerful and well suited for
CGI programming, but they require more time to learn than
HTML. Perl is probably the easier to pick up: much of Perl's
command syntax is "C-like", but the Perl command set is
smaller and is geared more toward the sort of text manipulation
that is often required in CGI programs.
In addition, Perl is technically an interpreted language,
while C is a compiled language. On the one hand
this means that a C program will probably execute faster
than a Perl program designed to perform the same task; on
the other hand, a Perl program is generally easier for a
novice to debug since you don't have to deal with the compilation
process after each modification of the code.
Speed vs. Ease of Use
Your choice of programming languages should not be based
solely on the ease of a language to learn, however. You
should also think carefully about the sort of tasks you
are likely to want your CGI programs to perform. As noted,
Perl is very well suited for text manipulations and related
tasks, but C would probably be preferred for a program that
needs to do a good deal of "number crunching". For most
Web applications number crunching is not very important
(unless you are into heavy-duty scientific applications,
for example) and speed is not an over-riding issue.
|