Posted to tcl by evilotto at Fri Dec 03 19:45:56 GMT 2010view raw

  1. set match "foo,bar,baz"
  2.  
  3. set inclusion [list]
  4. foreach term [split $match ,] {
  5. lappend inclusion *$term* -
  6. }
  7.  
  8. set inclusion [lreplace $inclusion end end {return 1}]
  9. proc matches {s} {
  10. switch -glob $s {*}$::inclusion default {return 0}
  11. }
  12. proc ckmatch {s} {
  13. if [matches $s] {puts "$s matches"} else {puts "$s nomatch"}
  14. }
  15.  
  16. ckmatch "hi, foo"
  17. ckmatch "hi, baz"
  18. ckmatch "hi, there"
  19.