Fisher
Fisher

Reputation: 422

Tcl: How to append multiple variables to a single line with a space between them?

Below code, append can add all file paths to a single line, but there is no space between them.
How to add a space between each path?

set all_path ""

foreach line $lines {
   set filepath [proc_get_file_path $line]
   ...
   #some commands
   ...
   append ::all_path $filepath
}

Expected output:

../path/a ../path/b ../path/c ...

Upvotes: 0

Views: 1283

Answers (1)

mrcalvin
mrcalvin

Reputation: 3434

How do you want to use all_path later on?

From the distance, this is where you would like to use a Tcl list:

set all_path [list]

foreach line $lines {
   set filepath [proc_get_file_path $line]
   # ...
   lappend all_path $filepath
}

The string representation of Tcl lists would also match your expectation re a whitespace delimiter. You can also assemble such a string manually, with append introducing a whitespace explicitly: append all_path " " $filepath. But maybe, this is not what you want to begin with ...

Upvotes: 1

Related Questions