๐Ÿ“œ
B.TECH III YEAR โ€ข II SEMESTER โ€ข R22

Scripting Languages - Lab Manual

Scripting Languages Laboratory โ€ข Program 14 Solution

๐Ÿ“˜ R22 Regulation ๐ŸŽ“ III Year ๐Ÿ“š II Semester ๐Ÿ“œ Scripting Languages ๐Ÿ’Ž Ruby โ€ข TCL โ€ข Perl ๐Ÿงช Lab Program
Aim of Program 14

Write a TCL script to (i) create a list (ii) append elements to the list (iii) Traverse the list (iv) Concatenate the list

โ† All Programs
Solution

Aim:

☛   Write a TCL script to
(i)create a list
(ii)append elements to the list
(iii)Traverse the list
(iv)Concatenate the list

Solution :

PROGRAM: (list_ops.tcl)

 
# (i) Create a list
set mylist1 {10 20 30}

puts "Original List: $mylist1"

# (ii) Append elements to the list
lappend mylist1 40
lappend mylist1 50

puts "After Appending Elements: $mylist1"

# (iii) Traverse the list
puts "Traversing the List:"
foreach item $mylist1 {
    puts $item
}

# (iv) Concatenate the list with another list
set myList2 {60 70 80}
set newList [concat $mylist1 $myList2]

puts "Concatenated List: $newList"



OUTPUT:

 
Original List: 10 20 30
After Appending Elements: 10 20 30 40 50
Traversing the List:
10
20
30
40
50
Concatenated List: 10 20 30 40 50 60 70 80



โ† Back to Scripting Languages Lab Programs ๐Ÿ“š All Lab Manuals