WebDeveloper.com �: Where Web Developers and Designers Learn How to Build Web Sites, Program in Java and JavaScript, and More!   
Web Developer Resource Directory WebDev Jobs
Animated GIFs
CSS Properties
HTML 4.01 Tags
Site Management
WD Forums

    Web Video
    Expression Web



    Forum, Blog, Wiki & CMS

 Site Management
    Domain Names
    Search Engines
    Website Reviews

 Web Development
  Business Issues

    Business Matters

    The Coffee Lounge
    Computer Issues

TCL: A CGI Scripting Language

by J.M. Ivler

What is Tcl and why use it for CGI scripting? Is it better than C? Shell? Perl? Tcl is the Tool Command Language created by Dr. John K. Ousterhout (formerly of The University of California, Berkeley, but now with Sun). The language is a very transportable shell language that has strong extensibility. It is generally used with Tk, a X-based GUI toolkit that makes prototyping graphical applications easy.

In many Usenet newsgroups there are constant flame wars on the usefulness of the language. Is it better than Perl? Is it better than Python? Why use it for one application vs. any other language? Tcl is not the "greatest" language for application building. Tcl is not the be-all and end-all language for application building. If you want a flame on languages, go to Usenet news. There's always a language war going on there.

Tcl is a good language because it is portable and extensible. It can run on platforms as varied as VAXen and Macs, as well as almost all flavors of Unix. It also allows for its library to be extended by the user, either in C or in Tcl. Its simple structure of "command argument argument" and strong string and list processing capabilities make it easy to use to perform complex parsing operations and string manipulation. Additionally, there is the ability to use associative arrays rather than being limited to numerical and multi-dimensional arrays.

Admittedly, there are some of these very same strengths in numerous other languages (LISP comes to mind most often, especially with the {} syntax of Tcl). In no way is Tcl being touted as the best language for scripting CGI code in, but it is an option.

In order to provide for easy extensibility of the forms to e-mail process, Tcl was chosen for its clear and clean style. Any site administrator can add hidden variables within the form, and easily add code to pick them out and provide additional functionality from within the CGI. A good example of that could be seen in the comments on what happened between the initial version and the upgrade printed here. Additionally, you can see the "code fragments" included in the main article. These fragments can be added to the email.tcl program to upgrade from 2.0 to the 2.1 version currently in development.

The code changes to the forms to email application, adding management functionality and limitations, as well as permitting an additional level of user functionality with hidden form variables, were accomplished in about 10 minutes of programming. No recompiles, no changing executables across numerous platforms.

As for Perl, Shell, and C? Yes, they are all great for CGI development. In fact the uncgi program that this code relies on is written in C. Tcl is right for small applications that you want to be able to make changes to, to extend and to contract functionality. And the ability to treat strings as lists and lists as stings provides for an enhanced ability to perform complex string and list manipulation easily.

To obtain a copy of Tcl see the following URL:

HTML5 Development Center

Recent Articles