传递给 join 的列表不会产生正确的输出 [英] List passed to join doesn't produce the correct output

查看:25
本文介绍了传递给 join 的列表不会产生正确的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
}

并像这样捕获结果:

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} "\\"]

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

Suppose I answered with Microsoft and Software Engineer as the input, I expected to get:

Microsoft\Software Engineer\20200509-1108

相反,我得到:

$company_name\$position\yearmonthday

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

Can someone elaborate on why? and how to fix it?

推荐答案

这只是归结为 引用.所以基本上你应该做的是使用不是大括号的东西,因为你想允许变量替换:

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" "\\"]

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

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] "\\"]

这篇关于传递给 join 的列表不会产生正确的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆