2

I need to parse through the array and find out a value at particular place in a TCL script

E.g., I have a string

set var "00 01 02 03"

I need to parse through the var to find what is there in the 3rd entry (02).

2 Answers 2

4

What you need is a TCL list. Remember the index counter starts at 0, so pass in 2 to lindex to find the 3rd element

% set my_list [list 00 01 02 03]
00 01 02 03
% lindex $my_list 2
02
4

Your string can be interpreted as a list, so you could use lindex to get the 3rd list element (counted starting with index 0):

lindex $var 2

Better would be (and works with different delimiters, too):

lindex [split $var " "] 2
1
  • 1
    Sometimes, it is easier to use regexp -inline -all to do the word identification step. Jun 12, 2012 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.