文件名划分和实例化
file name division and instantiation
set session_list [list ../../TIMING_ANALYSIS_CRPR/FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION ../../TIMING_ANALYSIS_CRPR/FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION ]
foreach j $session_list {
lappend x [regsub {^../../TIMING_ANALYSIS_CRPR/} $j ""]
}
foreach p $x {
lappend y [regsub {[^...]reports.15_03_10-22/SAVED_SESSION} $p ""]
}
foreach item $y {
lappend r "create_scenario -name $item"
}
foreach term $r {
lappend k " $term -image ./../ "
}
这是我创建的代码,期望的结果是:
create_scenario -name FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax -image ./../FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
create_scenario -name FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin -image ./../UNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
如何实现?我的主要问题是在最后一个 foreach
语句中调用 list"x"。有没有其他方法?
你可以(我什至会说应该)为此使用一个循环,因为你对列表的所有元素做同样的事情。根据我的理解,您需要获取 ../../TIMING_ANALYSIS_CRPR
之后的部分才能获取名称,图像是名称及其后的所有内容。
因此,与其删除不需要的内容,我宁愿'capture'像这样删除想要的内容:
# Just another way to have a list
set session_list {
../../TIMING_ANALYSIS_CRPR/FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
../../TIMING_ANALYSIS_CRPR/FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
}
foreach item $session_list {
regexp -- {TIMING_ANALYSIS_CRPR/(([^/]+).+)} $item -> image name
set result "create_scenario -name $name -image ./../$image"
puts $result
}
# Prints:
# create_scenario -name FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax -image ./../FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
# create_scenario -name FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin -image ./../FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
在正则表达式中,([^/]+)
将匹配并捕获除TIMING_ANALYSIS_CRPR/
之后的正斜杠字符以外的所有字符。然后加上 .+
(在 (([^/]+).+)
中获取名称,以及名称之后的所有其他内容,因为 .
匹配所有字符。
现在,正则表达式可能有点混乱,因为我们首先获取图像然后是名称,但那是因为外括号在前,然后名称在其中。
如果您不想(或者您觉得正则表达式太难),您可以尝试使用 file
命令来代替:
foreach item $session_list {
# Split on the directories
set elements [file split $item]
# Get the position of TIMING_ANALYSIS_CRPR
set id [lsearch $elements "TIMING_ANALYSIS_CRPR"]
# The name is just after it so...
set name [lindex $elements $id+1]
# The image is everything after the id:
set image [file join [lrange $elements $id+1 end]]
# Or if file join somehow is not using forward slashes:
# set image [join [list [lrange $elements $id+1 end]] "/"]
set result "create_scenario -name $name -image ./../$image"
}
注:我用的是Tcl8.6,如果你用的是Tcl8.4或更早的版本,部分语法要改
set session_list [list ../../TIMING_ANALYSIS_CRPR/FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION ../../TIMING_ANALYSIS_CRPR/FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION ]
foreach j $session_list {
lappend x [regsub {^../../TIMING_ANALYSIS_CRPR/} $j ""]
}
foreach p $x {
lappend y [regsub {[^...]reports.15_03_10-22/SAVED_SESSION} $p ""]
}
foreach item $y {
lappend r "create_scenario -name $item"
}
foreach term $r {
lappend k " $term -image ./../ "
}
这是我创建的代码,期望的结果是:
create_scenario -name FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax -image ./../FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
create_scenario -name FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin -image ./../UNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
如何实现?我的主要问题是在最后一个 foreach
语句中调用 list"x"。有没有其他方法?
你可以(我什至会说应该)为此使用一个循环,因为你对列表的所有元素做同样的事情。根据我的理解,您需要获取 ../../TIMING_ANALYSIS_CRPR
之后的部分才能获取名称,图像是名称及其后的所有内容。
因此,与其删除不需要的内容,我宁愿'capture'像这样删除想要的内容:
# Just another way to have a list
set session_list {
../../TIMING_ANALYSIS_CRPR/FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
../../TIMING_ANALYSIS_CRPR/FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
}
foreach item $session_list {
regexp -- {TIMING_ANALYSIS_CRPR/(([^/]+).+)} $item -> image name
set result "create_scenario -name $name -image ./../$image"
puts $result
}
# Prints:
# create_scenario -name FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax -image ./../FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
# create_scenario -name FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin -image ./../FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
在正则表达式中,([^/]+)
将匹配并捕获除TIMING_ANALYSIS_CRPR/
之后的正斜杠字符以外的所有字符。然后加上 .+
(在 (([^/]+).+)
中获取名称,以及名称之后的所有其他内容,因为 .
匹配所有字符。
现在,正则表达式可能有点混乱,因为我们首先获取图像然后是名称,但那是因为外括号在前,然后名称在其中。
如果您不想(或者您觉得正则表达式太难),您可以尝试使用 file
命令来代替:
foreach item $session_list {
# Split on the directories
set elements [file split $item]
# Get the position of TIMING_ANALYSIS_CRPR
set id [lsearch $elements "TIMING_ANALYSIS_CRPR"]
# The name is just after it so...
set name [lindex $elements $id+1]
# The image is everything after the id:
set image [file join [lrange $elements $id+1 end]]
# Or if file join somehow is not using forward slashes:
# set image [join [list [lrange $elements $id+1 end]] "/"]
set result "create_scenario -name $name -image ./../$image"
}
注:我用的是Tcl8.6,如果你用的是Tcl8.4或更早的版本,部分语法要改