&|What|switch using -matchvar|& &|Description|There is an error in manual|& &|Where|http://www.tcl.tk/man/tcl/TclCmd/switch.htm|& &|Requires|tdom, Tk|& &|tags|switch matchvar |& &|Updated|21.10.2011|& ---- I was looking for a solution for a problem like this: ====== set value_01 {abc} set value_02 {bcd} foreach value {abc bcd cde cdde def deeef any} { $value_01 {...} $value_02 {...} default {...} } ====== there is an example in the manual. I hoped this can help me, but it does not work. http://www.tcl.tk/man/tcl/TclCmd/switch.htm ====== set foo "abc" switch -regexp -matchvar foo -- $bar { a(b*)c { puts "Found [string length [lindex $foo 1]] 'b's" } d(e*)f(g*)h { puts "Found [string length [lindex $foo 1]] 'e's and\ [string length [lindex $foo 2]] 'g's" } } ====== this example raise an error: ====== can't read "bar": no such variable ====== so whats on? I did some trials: First on the switch: "-matchvar" to correct above example I had to change the use of the variables $bar and $foo: * $bar is not set * $foo is the matching varible inside the switch control ====== set foo "abc" catch {unset bar} switch -regexp -matchvar bar -- $foo { a(b*)c { puts "Found [string length [lindex $bar 1]] 'b's" } d(e*)f(g*)h { puts "Found [string length [lindex $bar 1]] 'e's and\ [string length [lindex $bar 2]] 'g's" } } ====== and the solution for my problem looks like this: ====== set value_01 {abc} set value_02 {bcd} foreach value {abc bcd cde cdde def deeef any} { switch -regexp -matchvar foo -- $value \ $value_01 { puts "\n ... \$value_01: $value_01" puts " ...... \$value: $value" puts " ...... \$foo: $foo" } \ $value_02 { puts "\n ... \$value_02: $value_02" puts " ...... \$value: $value" puts " ...... \$foo: $foo" } \ c(d*)e { puts "\n ... c(d*)e" puts " ...... \$value: $value" puts " ...... \$foo: $foo" } \ d(e*)f { puts "\n ... d(e*)f" puts " ...... \$value: $value" puts " ...... \$foo: $foo" } \ default { puts "\n ... default" puts " ...... \$value: $value" puts " ...... \$foo: $foo" } } ====== I hope this shows the aim of the "-matchvar" switch <>switch matchvar