Posted to tcl by sebres at Mon Apr 27 11:37:00 GMT 2020view raw

  1. set var1 {YNC 1 2;K1_SP4_SPA_CLEANUP_DIAMETER UGT0101_008;K1_SP4_SPA_FACING UGT0101_008;SYNC 2 2;K1_SP4_SPA_ROUGHING UGT0101_008}
  2. set var2 {SYNC 1 2;K2_SP4_CHECK_DIAMETER UGT010_0232;SYNC 2 2}
  3.  
  4. # some secret logic (at the moment returns 0 first 2 times called and always 1 hereafter):
  5. set i 0
  6. proc secret_knowledge {} {upvar i i; expr {[incr i] > 2}}
  7.  
  8. set var1 [split $var1 ";"]
  9. set var2 [split $var2 ";"]
  10. set res {}
  11. foreach v $var2 {
  12. if {[regexp {^SYNC } $v] && [secret_knowledge]} {
  13. lappend res NOOP
  14. }
  15. lappend res $v
  16. if {[regexp {^SYNC } $v] && [secret_knowledge]} {
  17. lappend res NOOP
  18. }
  19. }
  20. puts "expect:\tSYNC 1 2;K2_SP4_CHECK_DIAMETER UGT010_0232;NOOP;SYNC 2 2;NOOP"
  21. puts "result:\t[join $res ";"]"
  22.