TCL Tool Command Language
TCL Tool Command Language
* Simplicity
* Graphical User Interfaces
* Internationalization
* Extensibility
* Embeddability
* Easy debugging
* Regular expression support
Rapid development ? ? ?
?
Great regular expressions ? ?
Easily extensible ?
? Embeddable ?
Easy GUIs ?
? Internet and Web-enabled ? ? ?
?
Cross platform ? ? ?
Tcl/Tk Training 20/10/2004 14
Internationalization support ? ? ?
What is not covered ?
Internet resources:
* http://www.tcl.tk
* http://www.sun.com/960710/cover/tcl-syntax.html
* News group “news:comp.lang.tcl”
meminteg>
EXAMPLE 1.
% puts Hello
Hello
%
EXAMPLE 2.
EXAMPLE 5
% ;# Assign a number to variable Y
% set Y 1.24
1.24
%
% ;# Display the contents of Y
% puts $Y
1.24
%
EXAMPLE 9.
EXAMPLE 11.
EXAMPLE 14.
% set Z "Albany"
Albany
% set Z_LABEL "The Capitol of New York is: "
The Capitol of New York is:
%
% puts {$Z_LABEL $Z}
$Z_LABEL $Z
%
Tcl/Tk Training 20/10/2004 32
EXAMPLE 14. (Contd..)
$Z_LABEL $Z
% puts "\n....... examples of differences in nesting \{ and \" "
% expr $a + {5.33}
10.33
% expr $a + [set b 4.5]
9.5
% expr $a + int([set b 4.5])
9
- + ~ !
* / %
+ -
<< >>
< > <= >=
== !=
& ^ |
&& ||
x?y:z
EXAMPLE 22.
% expr ceil(4.5)
5.0
% expr floor(4.4)
4.0
% expr int(4.55)
4
STRING OPERATIONS
expr {"0x03" > "2"} will return 1.
will return 2,
Tcl/Tk Training 20/10/2004 47
Switch (Contd..) EXAMPLE 25.
switch -regexp aaab {
^a.*b$ -
b {format 1}
a* {format 2}
default {format 3}
}
will return 1, and
switch xyz {
a*
{format 2}
default
{format 3}
}
will return 3.
Tcl/Tk Training 20/10/2004 48
If-else
? if - Execute scripts conditionally
if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ...
?else? ?bodyN?
? The then and else arguments are optional
EXAMPLE 26.
% set x 1;
1
% if {$x != 1} {
puts "$x is != 1"
} else {
puts "$x is 1"
}
1 is 1
Tcl/Tk Training 20/10/2004 49
While
? while - Execute script repeatedly as long as a condition is met
? while test body
EXAMPLE 27.
set x 0
while {$x<10} {
puts "x is $x"
incr x
}
? A continue statement within body will stop the execution of the
code and the test will be re-evaluated.
? A break within body will break out of the while loop,
and execution will continue with the next line of code after body
Tcl/Tk Training 20/10/2004 50
For
? for - “For” loop
? for start test next body
EXAMPLE 28.
% foreach j $x {
puts "$j "
}
EXAMPLE 4.
EXAMPLE 5.
$m add separator