TCL (Tool Command Language) Interview Preparation Guide
Strengthen your TCL interview skills with our collection of 11 important questions. These questions will test your expertise and readiness for any TCL interview scenario. Ideal for candidates of all levels, this collection is a must-have for your study plan. Access the free PDF to get all 11 questions and give yourself the best chance of acing your TCL interview. This resource is perfect for thorough preparation and confidence building.11 TCL Questions and Answers:
1 :: What is TCL?
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(windos,all flavors of
linux,macintosh), easily deployed and highly extensible.
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(windos,all flavors of
linux,macintosh), easily deployed and highly extensible.
2 :: How TCL works?
After TCL installed on the machine, TCL information got
registred in the machine.
e.g:In Windows Registry
[HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\ActiveTcl]
The TCL path is updated in Machine environment.
e.g:
PATH=C:/Tcl/bin;%PATH%
Then TCL starts working.
1.TCL a Scripting Language. TCL binary comes with
name "tclsh".
When we use TCL,[ For example from Command prompt/Terminal
try to run tclsh ] it provides default prompt "%" to User
and asks for input.
#tclsh
%
How TCL works??
---------------
Each input from user is treated as TCL command.
After providing the command, tclsh fetch(gets) that command
and try to validate/compile/execute and populate(puts) the
message.
#tclsh
% hello
invalid command name "hello"
% set
wrong # args: should be "set varName ?newValue?"
%set say "Hello"
Hello
2. When we use TCL, we can provide a Script file as
argument.
Example: Create a file "HelloTickle.tcl" containing:
set say "Hello"
puts $say
Execute:
#tclsh HelloTickle.tcl
Hello
How TCL works??
---------------
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.
-----
registred in the machine.
e.g:In Windows Registry
[HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\ActiveTcl]
The TCL path is updated in Machine environment.
e.g:
PATH=C:/Tcl/bin;%PATH%
Then TCL starts working.
1.TCL a Scripting Language. TCL binary comes with
name "tclsh".
When we use TCL,[ For example from Command prompt/Terminal
try to run tclsh ] it provides default prompt "%" to User
and asks for input.
#tclsh
%
How TCL works??
---------------
Each input from user is treated as TCL command.
After providing the command, tclsh fetch(gets) that command
and try to validate/compile/execute and populate(puts) the
message.
#tclsh
% hello
invalid command name "hello"
% set
wrong # args: should be "set varName ?newValue?"
%set say "Hello"
Hello
2. When we use TCL, we can provide a Script file as
argument.
Example: Create a file "HelloTickle.tcl" containing:
set say "Hello"
puts $say
Execute:
#tclsh HelloTickle.tcl
Hello
How TCL works??
---------------
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.
-----
3 :: how to increment eacl element in a list?
eg: incrlist {1 2 3}
=>2 3 4
// 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
}
}
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
}
}
4 :: How to run a package in tcl?
source <package_name>
(or)
package require <name>
(or)
package require <name>
5 :: How increment a character? For example, I give a and I should get b?
set character "a"
set incremented_char [format %c [expr {[scan $character
%c]+1}]]
puts "Character before incrementing '$character' : After
incrementing '$incremented_char'"
set incremented_char [format %c [expr {[scan $character
%c]+1}]]
puts "Character before incrementing '$character' : After
incrementing '$incremented_char'"
6 :: How to extract "information" from "ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb" in tcl using a single command?
% 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
%
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
%
7 :: How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?
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
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
8 :: How do you find the length of a string without using string length command in TCL?
set str "lenghtofthisstring"
set len 0
set list1 [ split $str "" ]
foreach value $list1 {
incr len
}
puts $len
set len 0
set list1 [ split $str "" ]
foreach value $list1 {
incr len
}
puts $len
9 :: How to check whether a string is palindrome or not using TCL script?
Code for the above pseudo code.Check if it works!!!!!
gets stdin a
set len [ string length $a ]
set n [ expr $len/2 ]
for { set i 0 } { $i < $n } { incr i 1 } {
set b [ string index $a $i ]
set c [ expr $len - 1 - $i ]
set d [ string index $a $c ]
if {$b != $d} {
puts "not a palindrome"
exit
}
}
puts "Palindrome"
gets stdin a
set len [ string length $a ]
set n [ expr $len/2 ]
for { set i 0 } { $i < $n } { incr i 1 } {
set b [ string index $a $i ]
set c [ expr $len - 1 - $i ]
set d [ string index $a $c ]
if {$b != $d} {
puts "not a palindrome"
exit
}
}
puts "Palindrome"
10 :: Set ip address as 10.30.20.1 write a script to replace the 30 with 40?
here you can do this in multiple ways
1.regsub 30 $data 40 a
puts $a
this will give you the replaced string
2.string replace $data 3 4 40
this also will give you the replaced value
1.regsub 30 $data 40 a
puts $a
this will give you the replaced string
2.string replace $data 3 4 40
this also will give you the replaced value