Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listing values

Status
Not open for further replies.

mune77

Programmer
Oct 15, 2009
6
GB
I got two lists,
pinlist {A B C ..}
numlist {2 3 5 ..}

now I am trying to list it as table i.e.
pin num
--- ----
A 2
B 3
C 5
..

why does foreach command doesn't work in following way?

set i 1
foreach x [list $pinlist] {
puts stdout [format "%-32s %s \n" [lindex $numlist $i] [lindex $frqlist $i]]
incr i
}


 
What is the frqlist for?
Code:
[COLOR=#804040][b]set[/b][/color] pinlist [[COLOR=#804040][b]list[/b][/color] A B C]
[COLOR=#804040][b]set[/b][/color] numlist [[COLOR=#804040][b]list[/b][/color] [COLOR=#ff00ff]2[/color] [COLOR=#ff00ff]3[/color] [COLOR=#ff00ff]5[/color]]
[COLOR=#804040][b]set[/b][/color] my_fmt [COLOR=#ff00ff]"%s    %d"[/color]

[COLOR=#804040][b]set[/b][/color] i [COLOR=#ff00ff]0[/color]
[COLOR=#804040][b]foreach[/b][/color] x [COLOR=#008080]$pinlist[/color] {
  [COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color]  [COLOR=#008080]$my_fmt[/color] [COLOR=#008080]$x[/color] [[COLOR=#804040][b]lindex[/b][/color] [COLOR=#008080]$numlist[/color] [COLOR=#008080]$i[/color]]]
  [COLOR=#804040][b]incr[/b][/color] i
}
[COLOR=#804040][b]puts[/b][/color] {} 

[COLOR=#0000ff]# or when the pinlist contains each letter only once[/color]

[COLOR=#804040][b]foreach[/b][/color] x [COLOR=#008080]$pinlist[/color] {
  [COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#008080]$my_fmt[/color] [COLOR=#008080]$x[/color] [[COLOR=#804040][b]lindex[/b][/color] [COLOR=#008080]$numlist[/color] [[COLOR=#804040][b]lsearch[/b][/color] [COLOR=#008080]$pinlist[/color] [COLOR=#008080]$x[/color]]]]
}
Output
Code:
A    2
B    3
C    5

A    2
B    3
C    5
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top