Procedures With Variable Arguments
Procedures With Variable Arguments
body
}
#!/usr/bin/tclsh
proc helloWorld {} {
puts "Hello, World!"
}
helloWorld
Procedures with multiple arguments
#!/usr/bin/tclsh
proc add {a b} {
return [expr $a+$b]
}
puts [add 10 30]
Procedures with variable arguments
#!/usr/bin/tclsh
proc avg {numbers} {
set sum 0
foreach number $numbers {
Default arguments
#!/usr/bin/tclsh
proc add {a {b 100} } {
return [expr $a+$b]
}
puts [add 10 30]
puts [add 10]
Recursive procedure
#!/usr/bin/tclsh
proc factorial {number} {
if {$number <= 1} {
return 1
}
return [expr $number * [factorial [expr $number 1]]]
}
puts [factorial 3]
puts [factorial 5]
Writing a File
Reading a File
r,w a,r+,w+,a+
The "regexp" command is4 used to match a regular
expression in Tcl. A regular expression is a sequence of
characters that contains a search pattern. It consists of
multiple rules and the following table explains these rules
and corresponding use.