tcl - Working with pattern of list with values surrounded by {} -
i have data {} {abc}
, {abc} {}
,or {abc} {def}
, , want capture in 2 variables. tried:
foreach {fname} <program values> { set dfrom [lindex $fname 1] set rname [lindex $fname 2] print "fname- $fname" print "dfrom- $dfrom" print "rname- $rname" }
however, {}
not getting index.
from manual lindex, emphasis mine:
when presented single index, lindex command treats list tcl list , returns index'th element (0 refers first element of list)
so have use more this:
foreach {fname} <program values> { set dfrom [lindex $fname 0] set rname [lindex $fname 1] print "fname- $fname" print "dfrom- $dfrom" print "rname- $rname" }
and if you're on tcl 8.5 or newer versions, can use lassign
:
foreach {fname} <program values> { lassign $fname dfrom rname print "fname- $fname" print "dfrom- $dfrom" print "rname- $rname" }
Comments
Post a Comment