1Q).What is TCL?
Ans1: Tcl (Tool Command Language) is a very powerful but easy to learn dynamic programming language, suitable for a very wide range of uses, including web and desktop applications, networking, administration, testing and many more. Open source and business-friendly, Tcl is a mature yet evolving language that is truly cross platform (windows,all flavors of linux,macintosh), easily deployed and highly extensible.
Q 2). How TCL Works?
Ans2: Tcl takes the Argument as a file and try to read the file. TCL stores the file in memory and reads the file Line by Line and try to validate/compile. TCL provides the output and release the memory.
Q3).how to increment eacl element in a list? eg: incrlist {1 2 3} =>2 3 4
Ans3: // it works like incrlist 5 6 7 =>> 6 7 8
proc incrlist args {
set s 0
foreach s $args {
incr s 1
puts $s
}
}
//for list
proc incrlist list {
set s 0
foreach s $list {
incr s 1
puts $s
}
}
Q4).How to run a package in tcl ?
Ans4: source <package_name> (or) package require <name>
Q5).How increment a character? For example, I give a and I should get b?
Ans5:L set character “a”
set incremented_char [format %c [expr {[scan $character %c]+1}]] puts “Character before incrementing ‘$character’ : After incrementing ‘$incremented_char'”
Q6).How to extract “information” from “ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb” in tcl using a single command?
Ans6: % set
a “ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb”
ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb
% set b [string trimleft $a “abc”]
informationabcaaaaaabbbbbbbccbb
% set c [string trimright $b “abc”]
information
OR..
% set output [string trimright [string trimleft
$a “abc”] “abc”]
information
%
- value
Q7).How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?
Ans7: There are three solutions.
set a 192.30.40.1
set b [ string range $a 3 4 ]
set c [ string range $a 6 7 ]
set d [ string replace $a 3 4 $c ]
set e [ string replace $d 6 7 $b]
puts $e
===OR=====
set a 192.30.40.1
set b [ split $a .]
set u [lindex $b 0]
set v [lindex $b 3]
set x [lindex $b 1]
set y [lindex $b 2]
set z [join “$u $y $x $v” .]
puts $z
====OR====
set ip 192.30.40.1
regexp {([0-9]+.)([0-9]+.)([0-9]+.)([0-9]+)} $ip match 1st 2nd 3rd 4th
append new_ip $1st $3rd $2nd $4th
puts $new_ip
Q8).How do you find the length of a string without using string length command in TCL?
Ans8: set str “lenghtofthisstring”
set len 0
set list1 [ split $str “” ]
foreach value $list1 {
incr len
}
puts $len