我想用dict更新字典,但它似乎没有更新任何值。例如:
set test1 [dict create]
dict set test1 INST1 ports PORT1 type Q
dict set test1 INST1 ports PORT1 reset X
dict set test1 INST1 ports PORT2 type Qbar
dict set test1 INST1 ports PORT2 reset X
dict for {id data} $test1 {
set resetVal 0
dict with data {
dict for {portName portInfo} $ports {
dict with portInfo {
if {$type == "Q"} {
set reset $resetVal
} elseif {$type == "Qbar"} {
set reset [expr $resetVal ^ 1]
}
}
}
}
}
puts "PORT1=[dict get $test1 INST1 ports PORT1 reset]"
puts "PORT2=[dict get $test1 INST1 ports PORT2 reset]"
打印:
PORT1=X
PORT2=X
如何使用带有?
的dict更新“reset”的值