Posted to tcl by aspect at Tue Nov 08 23:05:51 GMT 2016view raw

  1. proc varswitch args {
  2. set switch [lindex $args end]
  3. set args [lrange $args 0 end-1]
  4. foreach {pattern body} $switch[set switch ""] {
  5. if {$body ne "-"} {
  6. set body [list string cat $body]
  7. }
  8. lappend switch $pattern $body
  9. }
  10. tailcall switch -glob {*}$args $switch
  11. }
  12.  
  13. foreach v {foo bar v Baz} {
  14. puts $v:[varswitch -nocase $v {foo 1 ba* 2 v 3 * 4}]
  15. }
  16.