TCL Interview Questions and Answers
bysonia, on May 19, 2017 12:48:18 PM
Q1. What is TCL?
ANS: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.
Q2. How TCL Works?
ANS: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
ANS:
// it works like incrlist 5 6 7 =>> 6 7 8
proc incrlist args {
设置S 0
foreach s $ args {
incr s 1
$ s
}
}
//列表
proc incrlist list {
设置S 0
foreach s $list {
incr s 1
$ s
}
}
Q4.How to run a package in tcl ?
ANS:source
Q5。角色如何增加?例如,我给A,我应该得到B?
ANS:
Lset 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?
ANS:
% set
“ CCCCCCCCCAAABBBBBAAAAABBINFORMATION ABCAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBCCBB”
CCCCCCCCCAAABBBBAAAAABBINFORMATIONABCAAAAAAAAAAAAAAAABBBBBBBBCCBB
% set b [string trimleft $a "abc"]
InformationAbcaaaaaaaaaBBBBBBBBCCBB
%set c [字符串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?
ANS:有三个解决方案。
set a 192.30.40.1
set b [ string range $a 3 4 ]
设置C [字符串范围$ A 6 7]
set d [ string replace $a 3 4 $c ]
set e [ string replace $d 6 7 $b]
$ e
===OR=====
set a 192.30.40.1
set b [ split $a .]
set u [lindex $b 0]
set v [lindex $ b 3]
设置x [lindex $ b 1]
设置y [lindex $ b 2]
set z [join "$u $y $x $v" .]
放$ z
====或====
设置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。您如何在不使用TCL中使用字符串长度命令的情况下找到字符串的长度?
ANS:set str "lenghtofthisstring"
set len 0
set list1 [ split $str "" ]
foreach value $list1 {
增量
}
放$ len
Q9。如何检查字符串是否使用TCL脚本?
ANS:Code for the above pseudo code.Check if it works!!!!!
得到stdin a
设置Len [字符串长度$ a]
set n [ expr $len/2 ]
for { set i 0 } { $i < $n } { incr i 1 } {
set b [ string index $a $i ]
设置C [expr $ len -1- $ i]
set d [ string index $a $c ]
如果{$ b!= $ d} {
放“不是回文”
exit
}
}
puts "Palindrome"
Q10. Set ip address as 10.30.20.1 write a script to replace the 30 with 40?
ANS:在这里您可以多种方式执行此操作
- regsub 30 $data 40 a puts $a this will give you the replaced string
- 字符串替换$数据3 4 40这也将为您提供更换