1.What are the different ways to initialize a variable. How
to differentiate global and local variables, explain it
through a simple tcl program.

2.Create a list of week days and print the first and last
character of each day using foreach command

3.Can you write a small program to verify the given input is
file or directory.Before checking, just ensure that the
file/dir exists or not in the given path. If the given
input is a file, findout the size and verify that the file
has all read ,write and execute permission.

Answers were Sorted based on User's Feedback



1.What are the different ways to initialize a variable. How to differentiate global and local vari..

Answer / devendra singh bhadoriya

2. % set days {monday tuesday wednasday thursday friday
saturday sunday}
monday tuesday wednasday thursday friday saturday sunday
% foreach day $days {
set str [split $day ""]
puts "[lindex $str 0]"
puts "[lindex $str end]"
}

Is This Answer Correct ?    17 Yes 6 No

1.What are the different ways to initialize a variable. How to differentiate global and local vari..

Answer / basavaraj

1.
a. Initializing using
set x 10 
lappend y 13

b. Initializing using out put of an expression 
set z [expr $x + $y ]

c . Initializing using a list
set m [list $x $y $z]

Is This Answer Correct ?    2 Yes 0 No

1.What are the different ways to initialize a variable. How to differentiate global and local vari..

Answer / amirtha

Ans for 3rd Question:
input is filename
if {file exists filename} {
set dir [ file isdirectory filename]
if {$dir == 1} { puts "filename is directory"
} else {
set fil [ file isfile filename]
set size [file size filename ]
puts "filename is file of size
file readable filename ;#to check file is readable by current user
file owned filename ;#to check file is owned by current user
file writable filename ;#to check file is writable by current user
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Tcl Interview Questions

How TCL works

1 Answers   Cisco,


{Anu Anudeep Anukumar Amar Amaravathi Aruna} is their any possibility to find the letter "a"in the given list? if yes how?

3 Answers   Cisco, HCL,


How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?

8 Answers   HCL, ONGC,


1.What are the different ways to initialize a variable. How to differentiate global and local variables, explain it through a simple tcl program. 2.Create a list of week days and print the first and last character of each day using foreach command 3.Can you write a small program to verify the given input is file or directory.Before checking, just ensure that the file/dir exists or not in the given path. If the given input is a file, findout the size and verify that the file has all read ,write and execute permission.

3 Answers   ATTO, HCL,


 write a regular expressions to fetch all the valid ip's

3 Answers   Alcatel,






How do you check whether a string is palindrome or not using TCL script?

10 Answers  


How to run a package in tcl

2 Answers  


Set ip address as 10.30.20.1 write a script to replace the 30 with 40 ?

9 Answers  


Problems with utf-8 between Mac and PC

1 Answers  


WHAT IS TCL?

4 Answers   Airtel,


how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4

9 Answers   Honeywell,


Write a proc to increment the ip by the given no. of times. The incremented IPs should be a valid one. Ex: proc <name> {ip no_of_incrments} { body }

2 Answers  


Categories