Cartoon Edmund

Home

Calendar

Contact

Knight Vision

Sitemap



Edmund J. Sutcliffe
Thoughtful Solutions, Creatively Implemented and Communicated

Edmund's TCL Quick Reference - 1 2
Click here for a printable version of this page.
Command
Use
Example
# Comment

# One line
# Another one

append append to end of variable value set foo "Hello "
append foo "World"
break exit loops  
catch used to recover from errors catch {procedure} [var]
eval build and evaluate a Tcl command before it is performed set fred "set flintstone 40"
eval $fred
40
exec execute subprocesses, includes external commands exec /usr/bin/ls -l
exit End a process  
expr evaluate an expression, normally arithmetic

expr 2 + 2

expr 10 * 2 + $var

file file I/O commands
Syntax: file keyword args
Includes commands such as read, write, etc.
 
for Definite looping construct
for  {set i 1} {$i <= 10} {incr i}
{
        coded statements here
}
foreach iterate over a list
set var [list ferrari porsche skoda]
foreach car $var {
coded statements here
}
format    
global makes a global variable global domination
set domination "we will"
Command
Use
Example
if
if/else
conditional statement
if { $var == 1 }
{
       set iable 4
}
else
{
set
iable 10
}
incr increment value by one set bob 1
incr bob
# bob is now 2
info various uses, but handy for checking if variables already exist if { [info exists somevar] }
join Joins a list of values together given a punctuation character.  
lappend Append a list of values to the end of a variable set var1 [ list 5 ]
set
var2 [ 10 15 20 ]
lappend
var1 var2
lindex extract an element from a list given its position lindex $list_var 3
linsert insert an element into a list  
list take values and make a list set some_var [list 1 2 3]
llength list length llength $somelist
lrange    
lreplace    
lsort sort the list. Use flags to change order and stuff  
proc create a procedure
proc thename { values }
{
somecode }


Cartoon Edmund

Quick Ref

Tech Tips

Travel Tips

Tech News

Images