Posted to tcl by aspect at Tue Nov 08 23:05:51 GMT 2016view raw
- proc varswitch args {
- set switch [lindex $args end]
- set args [lrange $args 0 end-1]
- foreach {pattern body} $switch[set switch ""] {
- if {$body ne "-"} {
- set body [list string cat $body]
- }
- lappend switch $pattern $body
- }
- tailcall switch -glob {*}$args $switch
- }
- foreach v {foo bar v Baz} {
- puts $v:[varswitch -nocase $v {foo 1 ba* 2 v 3 * 4}]
- }