You are on page 1of 7

#! /bin/tclsh8.

set f "input2.txt"
set fr [open $f r]

puts [read $fr]

close $fr

exit
set f "./input2.txt"

set fr [open $f r]

while {[gets $fr var] >= 0} {

puts "[lindex $var 0] --- [lindex $var 1]"

}
close $fr

exit
set f "./numbers.txt"

set fw [open $f w]

puts $fw "These are the numbers"

for {set i 0} {$i < 10} {incr i} {


puts $fw $i

close $fw
exit
proc fact {n} {

if {$n <= 1} {
return 1

} else {
return [expr $n * [fact [expr $n - 1]]]
}

puts [fact 3]
puts [fact 5]

exit
proc test1 {} {
global a
set b 333
puts "Hello"
puts "$a --- Test1"
set a 777
proc test2 {} {
global a
puts "world"
puts "$a --- Test2"
set a 999
upvar 2 x in
puts "$in --- inside test2"
return

}
test2
set a 222
return
}
set a 1000
set x 444
puts "VLSI-Synopsys"
test1
puts "$a --- after test1 call"

exit

proc test {a} {

foreach i $a {

puts $i

return 1
}

puts [test {AND OR NOT NAND}]

exit

proc add {{a 222} {b 555}} {

return [expr $a + $b]

puts [add 13.5 6.7]


puts [add 12.5]
puts [add]
# 1. Write a tcl script to read a list value from the terminal and display only the
even index
# numbered value
#
# 2. Write a tcl script to read a list of items from the user and get the response
from the user if he/she wants to change the items one after another, if the user
wants to change or update an item on that index, you must update the item in that
list. After the operation make sure my original list contains the updated item
values.
#
# 3. Write a tcl script to reverse a list without using lreverse
#

exit
set i 1

while {$i <= 10} {

if {$i == 6} {
incr i
continue

} else {

puts $i
incr i

}
}
exit
set var1 [list x1 x2 x3 [list g1 g2] h1]

set i 0

while {$i < [llength $var1]} {

puts "[lindex $var1 $i] --- while loop"

incr i

exit
set var1 [list x1 x2 x3 [list g1 g2] h1]

foreach i $var1 j [list j1 j2 j3] {

puts "$i --- $j"

}
exit
set var1 [list x1 x2 x3 [list g1 g2] h1]

foreach {i j} $var1 {

puts "$i --- $j"

exit
set i 0

while {$i < 10} {


puts $i
incr i

exit
set l [list l1 l2 l3]

set m [list m1 m2 m3 m4]

puts "$m --- $l"

puts [concat $l $m [list g1 g2 g3]]

set var [concat $m $l [list g1 g2 g3]]


puts $var

puts [exec ls]


exit

puts stdout "Hello world"

set a {a1 a2 a3 a4}


puts $a

puts -nonewline "ENter a list value: "


flush stdout

set c [gets stdin b]


puts "$c --- $b"

You might also like