i have following code:
proc list_backslash {} { array unset options array set options { -inputs {vdd} -outputs {vss} } set inputs { vdd2 vdd dvdd } set outputs { vss2 vss dvss } set updateoptions [ list \ -inputs $inputs \ -outputs $outputs ] array set options $updateoptions foreach {k v} [array options] { puts "$k => $v" } }
since have lot of key-value pairs in updateoptions
, there severe backslashitis! there better way code updateoptions
? tried subst
+ braces {}
, realized not preserve list structure dooming it.
generally speaking, if need continue line have use quoting mechanism of kind tcl. otherwise, command call ends when line ends. [
brackets]
can include multiple statements too; it's legal, really not recommended.
but mean you've got awkward alternatives. perhaps you'll best off doing this:
set updateoptions { -inputs $inputs -outputs $outputs } foreach {key value} $updateoptions { set options($key) [subst $value] }
the array set
command isn't efficient until huge numbers of options (many thousands) when code inside procedure.
or if you've got tcl 8.6, dict map
perhaps better:
array set options [dict map {key value} $updateoptions {subst $value}]
be aware subst
not particularly efficient command in tcl 8.6 except when used literal argument. that's because variable arguments, compiles them bytecode @ runtime.
Comments
Post a Comment