In TCL, how to append different content into a single file using the for
loop or foreach
loop?
Did you mean something like that?
set fo [open file a]
foreach different_content {"text 1" "text two" "something else" "some content"} {
puts $fo $different_content
}
close $fo
You open file file
in mode a
(append) and write to the file descriptor ($fo
in the example).
Update: If you want to append variable contents, you have to change the script to:
set fo [open file a]
foreach different_content [list $data1 $data2 $data3 $data4] {
puts $fo $different_content
}
close $fo