传递给 join 的列表没有产生正确的输出

List passed to join doesn't produce the correct output

我使用以下方法收集一些信息:

proc getJobinfo {question} {
    puts -nonewline "$question: "
    flush stdout
    gets stdin answer
    set cleanedanswer [string trim [::textutil::string::capEachWord $answer]]
    if {$cleanedanswer eq ""} {
       throw {Value Empty} {Input cannot be empty!}
    }
    return $cleanedanswer
}

并像这样捕获结果:

set systemTime [clock seconds]
set yearmonthday [clock format $systemTime -format %Y%m%d-%H%M%S]

set company_name [getJobinfo "Company Name"]
set position [getJobinfo "Position"]

我需要将它添加到列表中,以便加入它来创建路径。

根据 join 文档,我尝试了这个:

set submission_path [join {$company_name $position $yearmonthday} "\"]

假设我用 MicrosoftSoftware Engineer 作为输入回答,我希望得到:

Microsoft\Software Engineer200509-1108

相反,我得到:

$company_name$position\yearmonthday

有人可以详细说明原因吗?以及如何修复它?

它只会下降到 quoting。所以基本上你应该做的是使用不是大括号的东西,因为你想允许变量替换:

set submission_path [join "$company_name $position $yearmonthday" "\"]

上面的方法有效,但在这种情况下推荐的方法是使用列表命令:

set submission_path [join [list $company_name $position $yearmonthday] "\"]