I'd use format
here:
set id0 [list 1.1 2.1 3.1 4.1 5.1]
set str [format "\"%s\" \\" [join $id0 ,]]
puts $str
"1.1,2.1,3.1,4.1,5.1" \
سؤال
Say I ask tcl to print the following from within nested dictionary (containing rows and columns) - Reference: Brad Lanam
set id0 "[dict values [dict get $risedata constraints constraint $c 0]]"
...and I get this
1.1 2.1 3.1 4.1 5.1
Now I wish to change
{1.1 2.1 3.1 4.1 5.1}
to get {"1.1,2.1,3.1,4.1,5.1", \}
By adding the
1) ',' in between the values 2) ',' space and ' \' at the end 3) " at the start
I know I have to use join and linsert (I did join and need help with linsert)
1) ATTEMPT: set id0 [join $id0 ","]
to get 1.1,2.1,3.1,4.1,5.1
2) QUESTION: How do I convert 1.1,2.1,3.1,4.1,5.1
to {"1.1,2.1,3.1,4.1,5.1", \}
I tried set id0 [linsert [linsert $id0 end , "] 1 "]
but it is INCORRECT. Please help!
Ok so after that is done I want to
... write the line ({"1.1,2.1,3.1,4.1,5.1", \}
) over (overwrite) line 1 under 'values' which is "1.1,1.2,1.3,1.4,1.5", \
in this file format (called liberty (z.lib) - used for chip design). All other lines (rise_constraint ... etc) should be printed as is.
Snippet of z.lib
rise_constraint (constraint_template_5X5) {
index_1 ("0.01, 0.75, 0.72, 0.9, 0.8");
index_2 ("0.075, 0.025, 0.04, 0.3, 0.8");
index_3 ("0.084, 0.83, 3.99, 8.1, 19.44") ;
values ( \
"1.1,1.2,1.3,1.4,1.5", \
"2.1,2.2,2.3,2.4,2.5", \
"3.1,3.2,3.3,3.4,3.5", \
"4.1,4.2,4.3,4.4,4.5", \
"5.1,5.2,5.3,5.4,5.5", \
);
}
Note: I understand that For writing out a file, one would use open, close, dict, foreach, puts - to overwrite multiple lines (in this case 5 lines of 'values') - As wellexplained by Brad Lanam in a previous tcl query.
How do we use a foreach loop to iterate over 5 lines (in my .lib file format) and change it to my dict returned values???
Greatly appreciate your help on this!! Thank you so much! I'm a graduate student.
Reference: Brad Lanam
المحلول
I'd use format
here:
set id0 [list 1.1 2.1 3.1 4.1 5.1]
set str [format "\"%s\" \\" [join $id0 ,]]
puts $str
"1.1,2.1,3.1,4.1,5.1" \