CLEX420
CLEX420

Reputation: 31

Join the list in a variable

I have a list in one file called a_list as

top_a
.
.
.
top_e

Now I would like to append list into variable data which is read the a_list, just like:

set data [read $RTL]
puts "flag1:$data"

& output is something like this:

flag1:top_a
top_b
top_c
top_d
top_e

Now I am trying to insert into data through another variable which contains list, for example variable is:

set fr "top_f top_g"

I want output of data as

top_a
top_b
top_c
top_c
top_d
top_e
top_f
top_g

What should be the correct approach to do so,as I have tried for lappend or join but I am getting something like,

top_a top_b ... top_e {top_f top_f}

Any help would be much appreciated...

Edit: I am able to narrow is down with foreach as

foreach list $fr{
set a $list
}

I have something like:

top_f
top_g

How should i append variable 'a' into variable 'data' as:

top_a
top_b
top_c
top_c
top_d
top_e
top_f
top_g

Upvotes: 0

Views: 64

Answers (1)

Peter Lewerin
Peter Lewerin

Reputation: 13252

lappend data {*}$fr

if you have Tcl 8.5+, or

eval lappend data $fr

if you have 8.4 or older (unsupported, so upgrade in that case).

Documentation: eval, lappend, {*} (syntax)

Upvotes: 2

Related Questions