Foreach命令,启动错误

Foreach command ,initiation error

这是我的列表

  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 {
 set x  [string trimleft  $j  "../../TIMING_ANALYSIS_CRPR/ "]

}

foreach item $x {
puts "create_scenario -name $item "
}

所以我想要的是我对列表的输出为:

create_scenario -name 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/reports.15_03_10-22/SAVED_SESSION 

在最上面的代码中,它没有读取第一个 foreach 命令,也没有显示整个列表

您在每个循环中设置 x 的值,这将导致 x 值被覆盖。

你必须使用lappend命令

 foreach j $session_list {
      lappend x  [string trimleft  $j  "../../TIMING_ANALYSIS_CRPR/ "]
 }

 foreach item $x {
     puts "create_scenario -name $item "
 }

输出:

create_scenario -name 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/reports.15_03_10-22/SAVED_SESSION 

参考:lappend

[string trimleft] 并不像您想象的那样。该行:

string trimleft  $j  "../../TIMING_ANALYSIS_CRPR/ "

基本上意味着:删除字符./TIMNG_ANLYSCR and P and (single space) 形成字符串的左边。

你想要的是 regsub:

regsub {^../../TIMING_ANALYSIS_CRPR/} $j ""