问题
I collect some information using the following method:
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
}
and capture the result like this:
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"]
I need to add it to a list so that I can join it to create a path.
Following the join documentation I tried this:
set submission_path [join {$company_name $position $yearmonthday} "\\"]
Suppose I answered with Microsoft
and Software Engineer
as the input, I expected to get:
Microsoft\Software Engineer\20200509-1108
Instead I get:
$company_name\$position\yearmonthday
Can someone elaborate on why? and how to fix it?
回答1:
It's only coming down to quoting. So essentially what you should do instead is to use something that's not braces because you want to allow for variable substitution:
set submission_path [join "$company_name $position $yearmonthday" "\\"]
The above works, but the recommended way to do it in this case, since you're effectively joining a list, is to use the list command:
set submission_path [join [list $company_name $position $yearmonthday] "\\"]
来源:https://stackoverflow.com/questions/61699000/list-passed-to-join-doesnt-produce-the-correct-output