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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -