Reputation: 45
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 ./../ "
}
This is the code I created, the desired result is :
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
How do I achieve this? My main problem is calling list"x" in the last foreach
statement. Is there any alternative way?
Upvotes: 1
Views: 38
Reputation: 71598
You can (and I would even say should) use a single loop for that since you are doing the same thing for all elements of the list. From my understanding, you need to get the part after ../../TIMING_ANALYSIS_CRPR
to get the name and the image is the name and everything after it.
So instead of removing what's not wanted, I would rather 'capture' what's wanted like this:
# 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
In the regexp, ([^/]+)
will match and capture all characters except the forward slash character after TIMING_ANALYSIS_CRPR/
. Then this, plus .+
(in (([^/]+).+)
gets the name, and everything else after the name since .
matches all characters.
Now, the regex can be a bit confusing since we are first getting the image then the name, but that's because the outer parentheses comes first, then the name is inside it.
If you don't want to (or you find regex too hard), you might try using file
commands instead:
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"
}
Note: I am using Tcl8.6 if you are using Tcl8.4 or earlier versions, some of the syntax would have to be changed
Upvotes: 1