TCL Lists
TCL Lists
A list is an ordered collection of elements where each element can have any string value such as a
Lists are used in Tcl to deal with collections of things, such as all the users in a group or all the files in a
directory
Lists are represented as strings and processed to form individual items when required.
or
or
puts $colorList1
puts $colorList2
puts $colorList3
concat and
list
These commands produces a list as a result. Note the resultant list differs based on the
command used.
concat {a b c} {d e} f {g h i}
⇒abcdef ghi
list {a b c} {d e} f {g h i}
⇒ {a b c} {d e} f {g h i}
set x {a b c}
set y {d e f}
set z [concat $x $y]
z ⇒ abcdef
z ⇒ abcdef
z ⇒ {a b c} {d e f}
llength listName
#!/usr/bin/tclsh
#!/usr/bin/tclsh
blue
#!/usr/bin/tclsh
puts $var
puts $var
puts $var
puts $colour1
puts $colour2
orange
blue
14 VIT - SENSE 09-01-2024
Sorting a list
The syntax for sorting a list is given below.
puts $var
-1
First argument to the split is the string to be split up and the second argument is the split
character.
set x a/b/c
split $x /
=>a b c
set x /a/b/c
split $x /
=> { } a b c
It concatenates the list elements together with a separator string between them.
First argument to the join is the list to be joined up and the second argument is the join character.
join {{} a b c} /
/a/b/c
expr [join $x +]
141