Find Interview Questions for Top Companies
Ques:- how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4
Asked In :-
Right Answer:
```tcl
set list {1 2 3}
set incrList [lmap item $list {expr {$item + 1}}]
puts $incrList
```
Comments
Admin May 17, 2020

set incrlist { 1 2 3 }
foreach element $incrlist {
set new_element [ expr $element + 1 ]
lappend new_incrlist $new_element
}
puts $new_incrlist

Admin May 17, 2020

set list {1 2 3}
regsub -all {(d+)} $list "[expr \1 + 1]" new_list
set result [eval concat "" $new_list]

Ques:- How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?
Asked In :-
Comments
Admin May 17, 2020

set ip "192.30.40.1"
regsub {(d+).(d+).(d+).(d+)} $ip "\1.\3.\2.\4" new_ip
puts $new_ip

Admin May 17, 2020

set x 192.30.40.1
set srcStr {([0-9]+).([0-9]+).([0-9]+).([0-9]+)}
regexp $srcStr $x - d1 d2 d3 d4
regsub $srcStr $x "$d1.$d3.$d2.$d1" x
puts $x

Ques:- How to extract “information” from “ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb” in tcl using a single command?
Asked In :-
Comments
Admin May 17, 2020

set i "ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb"
set n [regexp {.*(information).*} $i ma s]
puts "$s"

Admin May 17, 2020

puts [string trim "ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb" "abc"]
verified result.
works 100% fine.

Ques:- How increment a character? For example, I give ‘a’ and I should get ‘b’.
Asked In :-
Comments
Admin May 17, 2020

set ch a
set l [scan $ch %c]
incr l
set m [format %c $l]
puts "$m"

Admin May 17, 2020

set character "a"
set incremented_char [format %c [expr {[scan $character
%c]+1}]]
puts "Character before incrementing '$character' : After
incrementing '$incremented_char'"

Ques:- Problems with utf-8 between Mac and PC
Asked In :-
Right Answer:
The main problems with UTF-8 between Mac and PC often arise from differences in how text editors handle line endings and file encoding. Mac may use different default settings for encoding and line endings compared to Windows, leading to issues like incorrect character display or corrupted text. To avoid these problems, ensure that both systems use the same text encoding (UTF-8) and consistent line endings (LF for Unix/Mac, CRLF for Windows) when sharing files.
Comments
Admin May 17, 2020

OK, I have a small test file that contains utf-8 codes. Here
it is (the language is Wolof)
Fˆndeen d‘kk la bu ay wolof aki seereer a fa nekk. DigantŽem
ak Cees jur—om-benni kilomeetar la. MbŽyum gerte ‘pp ci
diiwaan bi mu
that is what it looks like in a vanilla editor, but in hex
it is:
xxd test.txt
0000000: 46cb 866e 6465 656e 2064 e280 986b 6b20 F..ndeen
d...kk
0000010: 6c61 2062 7520 6179 2077 6f6c 6f66 2061 la bu ay
wolof a
0000020: 6b69 2073 6565 7265 6572 2061 2066 6120 ki seereer
a fa
0000030: 6e65 6b6b 2e20 4469 6761 6e74 c5bd 656d nekk.
Digant..em
0000040: 2061 6b0d 0a43 6565 7320 6a75 72e2 8094 ak..Cees
jur...
0000050: 6f6d 2d62 656e 6e69 206b 696c 6f6d 6565 om-benni
kilomee
0000060: 7461 7220 6c61 2e20 4d62 c5bd 7975 6d20 tar la.
Mb..yum
0000070: 6765 7274 6520 e280 9870 7020 6369 2064 gerte
...pp ci d
0000080: 6969 7761 616e 2062 6920 6d75 0d0a iiwaan bi mu..
The second character [cb86] is a non-standard coding for
a-grave [à] which is found quite consistently in web
documents, although in 'real' utf-8, a-grave would be c3a0.
Real utf-8 works beautifully on Macs and under Windows.
I handle the fake utf-8 by using a character map which
included the pair { ˆ à } because that little caret is what
cb86 generates, and everything works fine ON A MAC for
displaying text (in a text widget) like this:
Fàndeen dëkk la bu ay wolof aki seereer a fa nekk. Digantéem ak
Cees juróom-benni kilomeetar la. Mbéyum gerte ëpp ci diiwaan
bi mu
On a PC - using the same file (shared) the first three
characters read in are46 cb 20 (using no fconfigure). I have
run through ALL the possible encodings and can never get the
same map to work. [There are twenty that will allow 46 cb 86]
Sorry this is so long, but if anyone has a clue, I would
love to hear it.
Tel Monks

Ques:- How to run a package in tcl
Asked In :-
Right Answer:
To run a package in Tcl, use the `package require` command followed by the package name and version. For example:

```tcl
package require packageName version
```
Comments
Admin May 17, 2020

source <package_name>
(or)
package require <name>

Admin May 17, 2020

TCL OOPS

Ques:- How do you check whether a string is palindrome or not using TCL script?
Asked In :-
Right Answer:
```tcl
proc isPalindrome {str} {
set reversed [string reverse $str]
return [string equal $str $reversed]
}

# Example usage:
set testString "racecar"
puts [isPalindrome $testString] ;# Outputs 1 (true) if palindrome
```
Comments
Admin May 17, 2020

Hi!! i have written 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"

Admin May 17, 2020

proc palindrome {iStr} {
if {[ string match -nocase $iStr [string reverse $iStr]]} {
puts "Palindrome"
} else {
puts "Not a Palindrome"
}
}
palindrome "Sator Arepo Tenet Opera Rotas"
Palindrome

Ques:- How do you find the length of a string without using string length command in TCL??
Asked In :-
Right Answer:
You can find the length of a string in Tcl without using the `string length` command by using the `llength` command on the list created from the string. For example:

```tcl
set myString "Hello, World!"
set length [llength [split $myString ""]]
```
Comments
Admin May 17, 2020

set str "lenghtofthisstring"
set list1 [ split $str "" ]
foreach value $list1 {
incr len
}
puts $len

Admin May 17, 2020

set str "lenghtofthisstring"
puts [llength [ split $str "" ]]

Ques:- Where can find the sample tcl programs?
Asked In :-
Right Answer:
You can find sample Tcl programs on websites like Tcler's Wiki, GitHub repositories, and the official Tcl documentation site.
Ques:- Set ip address as 10.30.20.1 write a script to replace the 30 with 40 ?
Asked In :-
Right Answer:
```tcl
set ip "10.30.20.1"
set new_ip [regsub {30} $ip "40"]
puts $new_ip
```
Comments
Admin May 17, 2020

% set ip 10.30.20.1
10.30.20.1
% regsub -all {30} $ip {40} ip
1
% puts $ip
10.40.20.1
%

Admin May 17, 2020

In above answer if you have IP like 10.30.30.1 then it replace for all 30 with 40.But here i guess intention is just to replace one octet with 40.So following solves that issue:
set a 10.30.2.1
set b [ string replace $a 3 4 40 ]
puts $b

Ques:- how to write the startup scripts in winrunner? can any body explain with example code?
Asked In :-
Right Answer:
In WinRunner, startup scripts can be written in the "Startup" section of the Test Script Editor. You can use the `start_app` function to launch an application and perform initial setup tasks. Here’s an example:

```tcl
# Startup script example in WinRunner

# Start the application
start_app("C:\Path\To\YourApplication.exe");

# Wait for the application to load
wait_for_window("Your Application Window Title");

# Perform initial setup actions
set_window("Your Application Window Title", 1);
click("Login Button");
type("Username Field", "your_username");
type("Password Field", "your_password");
click("Submit Button");
```

This script starts the application, waits for the window to appear, and performs login actions. Adjust the paths and identifiers as needed for your specific application.
Ques:- WHAT IS TCL?
Asked In :-
Right Answer:
Tcl (Tool Command Language) is a scripting language designed for embedding into applications, providing a simple syntax for controlling and automating tasks. It is often used for rapid prototyping, scripted applications, and GUIs.
Comments
Admin May 17, 2020

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.
Developer :Ousterhout
Current Version : 8.5
Regards,
Rajkumar

Admin May 17, 2020

TCL(Tool Command Language) ia a very simple and powerful
scripting language.It can source script or enter commands
and scripts. TCL shell provides interface to the interpreter
of the commands for execution.

Ques:- Test case on windows calculator?
Asked In :-
Right Answer:
1. Open the Windows Calculator application.
2. Verify the calculator opens without errors.
3. Test basic arithmetic operations:
- Input "2 + 2" and press "="; expect result "4".
- Input "5 - 3" and press "="; expect result "2".
- Input "4 * 3" and press "="; expect result "12".
- Input "8 / 2" and press "="; expect result "4".
4. Test decimal calculations:
- Input "2.5 + 1.5" and press "="; expect result "4.0".
5. Test order of operations:
- Input "3 + 5 * 2" and press "="; expect result "13".
6. Test clear function:
- Input "10 + 5" and press "C"; expect display to be "0".
7. Test memory functions:
- Press "M+" with a value, then "MR
Ques:- if i give in numbers output should be in characters example : set a 23 o/p twentythree
Asked In :-
Right Answer:
```tcl
proc numberToWords {num} {
set words {
0 "zero" 1 "one" 2 "two" 3 "three" 4 "four" 5 "five" 6 "six" 7 "seven" 8 "eight" 9 "nine"
10 "ten" 11 "eleven" 12 "twelve" 13 "thirteen" 14 "fourteen" 15 "fifteen" 16 "sixteen"
17 "seventeen" 18 "eighteen" 19 "nineteen" 20 "twenty" 30 "thirty" 40 "forty" 50 "fifty"
60 "sixty" 70 "seventy" 80 "eighty" 90 "ninety"
}
if {$num < 20} {
return [dict get $words $num
Comments
Admin May 17, 2020

set oned { one two three four five six seven eight nine ten }
set towd { ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen }
set multten {ten twenty thirty forty fifty sixty seventy eighty ninety}
set num 67
set len [string len $num]
if {$len == 1} {
set first [regexp -inline {[0-9]} $num]
set first [lindex $oned $first-1]
puts $first
}
if {$len == 2 && $num < 19} {
set first [regexp -inline {[0-9]$} $num]
set first [lindex $towd $first]
puts $first
}
if {$len == 2 && $num > 19} {
set first [regexp -inline {[0-9]} $num]
set first [lindex $multten $first-1]
set second [regexp -inline {[0-9]$} $num]
set second [lindex $oned $second-1]
puts "$first $second"
}

Ques:- Write a program to increment IP address to +10 and verify it is correct ip or not ?? example my ip is 172.122.132.143 increment this ip to +10 and verify it is valid ip or not
Asked In :-
Right Answer:
```tcl
proc increment_ip {ip increment} {
set octets [split $ip "."]
set last_octet [lindex $octets 3]
set new_last_octet [expr {$last_octet + $increment}]

if {$new_last_octet >= 256} {
set carry [expr {$new_last_octet / 256}]
set new_last_octet [expr {$new_last_octet % 256}]
set octets [lmap octet {0 1 2} {expr {[lindex $octets $octet] + [lindex $octets $octet] == 255 ? 1 : 0]}}]
set octets(3) $new_last_octet
for {set i 3} {$i >= 0} {incr i -1} {
if {[lindex $octets $i] >= 256} {
set
Comments
Admin May 17, 2020

set ip "10.255.255.255"
set list [split $ip "."]
set oct1 [lindex $list 0]
set oct2 [lindex $list 1]
set oct3 [lindex $list 2]
set oct4 [lindex $list 3]
if {$oct4>254} {
set oct4 0
set oct3 [expr $oct3+10]
if {$oct3>255} {
set oct3 0
set oct3 [expr $oct3+10]
if {$oct2>255} {
set oct2 0
set oct3 [expr $oct1+10] }
if {$oct1>255} {
set oct1 0
}}} else {
set oct4 [expr $oct4+10]
}
puts "$oct1.$oct2.$oct3.$oct4"

Ques:- {Anu Anudeep Anukumar Amar Amaravathi Aruna} is their any possibility to find the letter “a”in the given list? if yes how?
Asked In :-
Comments
Admin May 17, 2020

puts "searching variable a"
set list_4 [list Anu Anudeep Anukumar Amar Amaravathi Aruna]
foreach item $list_4 {
set elem [split $item ""]
foreach var $elem {
if {$var == "a"} {
puts $item
}
}
}

Admin May 17, 2020

set str {Anu Anudeep Anukumar Amar Amaravathi Aruna}
foreach i $str {
if {[regexp {(A)} $i match ] } {
puts $match
}
}

Ques:- how to remote log in to a system A to system B ,execute commands in it and collect the log in system A from B using TCL script??  
Asked In :-
Right Answer:
You can use the `exec` command in Tcl to execute remote commands via SSH. Here's a simple example:

```tcl
set remoteHost "user@systemB"
set command "your_command_here"
set logFile "output.log"

# Execute the command on the remote system and capture the output
set output [exec ssh $remoteHost $command]

# Write the output to a log file on system A
set fileId [open $logFile "w"]
puts $fileId $output
close $fileId
```

Make sure you have SSH access set up between the two systems.
Comments
Admin May 17, 2020

From System A, ssh to system B and get the spawn ID of System B into System A , use "set val [send -i $spawn_id <command>]" which would run a command in System B from system A context, Now whatever is content in val (puts $val) would be the logs from System B run in System A.

Ques:- Which scripting language is better among TCL Perl and Python and why? 
Asked In :-
Right Answer:
The choice between Tcl, Perl, and Python depends on the specific use case. Python is generally considered better for its readability, extensive libraries, and community support, making it suitable for a wide range of applications. Tcl is often preferred for embedded applications and GUI development, while Perl excels in text processing and system administration tasks.
Comments
Admin May 17, 2020

It is my opinion that on which task I have to use which language.

Ques:- write a program to the given ip is valid private address or not(192.168.1.1)?
Asked In :-
Right Answer:
```tcl
proc isPrivateIP {ip} {
set octets [split $ip "."]
if {[llength $octets] != 4} {
return 0
}
set first [lindex $octets 0]
set second [lindex $octets 1]
if {($first == 10) || ($first == 172 && $second >= 16 && $second <= 31) || ($first == 192 && $second == 168)} {
return 1
}
return 0
}

set ip "192.168.1.1"
puts [isPrivateIP $ip]
```
Comments
Admin May 17, 2020

#10.0.0.0 through 10.255.255.255
#169.254.0.0 through 169.254.255.255
#172.16.0.0 through 172.31.255.255
#192.168.0.0 through 192.168.255.255
set ip 192.168.10.1
if {[regexp {^(10|169|172|192).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])} $ip match 1st 2nd 3rd 4th]} {
puts $match
puts "$1st
$2nd
$3rd
$4th" }

Admin May 17, 2020

#169.254.0.0 through 169.254.255.255
#172.16.0.0 through 172.31.255.255 
#192.168.0.0 through 192.168.255.255
#10.0.0.0 10.255.255.255
set a "10.78.80.2" or 
// a could be any private range the below regexp will match ,if u provide other than private range it will throw an error 
regexp {^(10|169|172|192).([0-9]+|[0-9][0-9]+|1[0-9][0-9]+|2[0-4][0-9]+|25[0-5]+).([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])} $a match 
puts $match

Ques:-  write a regular expressions to fetch all the valid ip’s
Asked In :-
Comments
Admin May 17, 2020

set ip "244.168.123.23"
regexp {([0-9]+).([0-9]+).([0-9]+).([0-9]+)} $ip match a b c d 
if {$a <=255 & $b <=255 & $c <=255  & $d <=255} {
puts "$ip is valid ip address"
} else {
puts "$ip is not valid address"
}

Admin May 17, 2020

Hi,
check this out 
====================
I am trying to match first octet in an valid IP address ,Please copy and paste for the remaining octet
regexp {^([1-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).} $ip match first
I have matched in below order ...
1-10
11-99
100-199
200-248
250-255



AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users