Compare 比较TCL中的两条路径

Compare 比较TCL中的两条路径,compare,tcl,matching,Compare,Tcl,Matching,我在正在读取的文件中的Linux/home/probil/xilinxip/pll1.xci中有一个路径。现在,我想将这个路径与该文件中存在的所有路径进行比较,如果匹配,则打印文件在该文件中。 文件有许多类似格式的路径。如果我使用If语句,它将给出错误 set xci_source_files_ip [file normalize "$origin_dir/xci_source_files.f"] set xci_source [open $xci_source_files_ip r] whi

我在正在读取的文件中的Linux/home/probil/xilinxip/pll1.xci中有一个路径。现在,我想将这个路径与该文件中存在的所有路径进行比较,如果匹配,则打印文件在该文件中。 文件有许多类似格式的路径。如果我使用If语句,它将给出错误

set xci_source_files_ip [file normalize "$origin_dir/xci_source_files.f"]
set xci_source [open $xci_source_files_ip r]

while {[gets $xci_source file] > -1} {
set file $file
set file [file normalize $file]
#if{[$file] eq ["/home/probil/xilinxip/pll1.xci"]}{
   puts "file matched"
}

文件名应该作为简单字符串进行比较(通常在规范化之后,尽管有些情况下您不想这样做)。因此,您可以这样做:

if {$file eq $file2} {
    puts "They're the same thing!"
}
或者,通过标准化:

if {[file normalize $file] eq [file normalize $file2]} {
    puts "They're the same thing!"
}
如果您正在与已知已为规范化文件名的常量进行比较,则可以省略显式规范化(但作为表达式语法的一部分,文件名文字需要在表达式中使用双引号或大括号):

不要将它们单独放在方括号中尽管(
如果{[$file1]eq[“…]”}
),因为方括号用于Tcl中的命令替换;您最终尝试用一个相当奇怪的名称调用命令,但(通常)不起作用

if {$file eq "/home/probil/xilinxip/pll1.xci"} {
    puts "They're the same thing!"
}
if {[file normalize $file] eq "/home/probil/xilinxip/pll1.xci"} {
    puts "They're the same thing!"
}