TCL Scripting Session-18-30
TCL Scripting Session-18-30
lab1
String Manipulation
• Strings are the basic data type in Tcl, so there are a large number of functions
supported in Tcl to manipulate strings through string command.
String Manipulation
String Manipulation
• Commands:
String Manipulation
Flow Control
• Example:
set sel 3
if {$sel == 1} {
puts "Selection $sel"
} elseif {$sel == 2} {
puts "Selection $sel"
} else {
puts "Invalid selection"
}
Flow Control
Lists
• List is a collection of elements separated by white space, each element with a relative
position within the List. Number of elements in the List defines the size of the List and an
empty List will contain no elements.
• There are a large number of functions supported in Tcl to manipulate lists as list,
lappend, lindex, linsert, llength, Irange, Isearch, concat and join commands.
• Creation of list:-
set mylist “1 2 3 4 5“
set mylist {1 2 3 4 5}
set mylist [list 1 2 3 4 5]
Lists
Loops
• While loop
• For loop
Loops
Loops
• Foreach loop
foreach implements a loop where the loop variable(s) iterates over all
the elements of a list(s).
? Loops
Loop Control Statements
• break
break statement used to exist the loop and the program resumes at the next
statement following the loop.
• continue
continue statement used to skip the current loop iteration and jumps to execute the
next iteration in the loop.
• An array is a systematic arrangement of a group of elements using indices. The syntax for the
conventional array is shown below:
• Creation of Array :-
Index Value
set languages(0) Tcl 0 Tcl
set languages(1) "C Language"
1 C Language
• Example :-
Procedures
I/O Files Handling
• Tcl supports file handling with the help of the built in commands open, read, puts, and close.
• The regsub command is used to do string substitution based on pattern match string.
• Switches :-
Switch Description
-nocase Used to ignore case
-all Used to substitute all matched strings
RegSub