Thursday, May 29, 2014

TCL and Expect Library

Source: http://www.tcl.tk/man/tcl8.5/tutorial/Tcl31.html

WORK IN PROGRESS

Preamble 

Well, today I have to write an "expect" script to automate some of the lab work that I need to do.  I already have basic library like the login procedure and etc done on a previous project.  Currently, I have that in a file and usually just "source ..." them in.  But why get stuck using just "source ...".  Its easy, but I don't think it is cool. LOL.  Let's try to look at some of the alternatives.

The following is a direct quote from Tcl31.html's tutorial.  The exact URL locates on the top of the page.

Using packages

The package command provides the ability to use a package, compare package versions, and to register your own packages with an interpreter. A package is loaded by using the package require command and providing the package name and optionally a version number. The first time a script requires a package Tcl builds up a database of available packages and versions. It does this by searching for package index files in all of the directories listed in the tcl_pkgPath and auto_path global variables, as well as any subdirectories of those directories. Each package provides a file called pkgIndex.tcl that tells Tcl the names and versions of any packages in that directory, and how to load them if they are needed.

It is good style to start every script you create with a set of package require statements to load any packages required. This serves two purposes: making sure that any missing requirements are identified as soon as possible; and, clearly documenting the dependencies that your code has. Tcl and Tk are both made available as packages and it is a good idea to explicitly require them in your scripts even if they are already loaded as this makes your scripts more portable and documents the version requirements of your script.


No comments:

Post a Comment