Simple TCL Question Issue

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Simple TCL Question Issue

  • Creator
    Topic
  • #53749
    Jon Melin
    Participant

      Hello,

      I am having a lot of issues with a seemingly very simple TCL proc. I am bringing in an X12 file and replacing one word if a trigger word exists in the file. I am including two snippets of code, one that works and one that doesn’t. The one that just replaces one word with another seems to work just fine (tested and it just replaced all instances as designed)

      The issue is when I try to use a regsub with an IF statement around it I either get “extra characters after closing bracket” —- Which there isn’t, I even rewrote it and brought it into a text editor to verify, or I get “Invalid command name “2” — when I am not calling a command name “2”

      Please provide suggestions if you have any. This is very frustrating since it isn’t anything complicated being done.

      ~Jon

    Viewing 2 reply threads
    • Author
      Replies
      • #78824
        Robert Milfajt
        Participant

          Try this for your if statement, but the problem appears to be the fact that regsub by itself is not a valid command within the then part of an if statement.

          Code:

          if {$exists > 0} {set replace [regsub -all — {(?b)} $msg {WITHTHIS}]}

          Hope this helps,

          Robert Milfajt
          Northwestern Medicine
          Chicago, IL

        • #78825
          Jon Melin
          Participant

            Wow. It was that simple (more testing to do, but initial results are good!). I have been pulling my hair out! I thought I had tried that before but after revision 100 I lose track. Thank you very much.

          • #78826
            Bob Richardson
            Participant

              Greetings,

              The regsub returns the number of hits so your set format will not work

              here.   However regsub has the option to create a variable with the new

              values.

              Here is a simple interactive example running in a TCL shell:

              tcl>set val “this is a value”

              this is a value

              tcl>regsub -all — {value} $val {newvalue} newvariable

              1

              tcl>echo $newvariable

              this is a newvalue

              Hope this helps you.

          Viewing 2 reply threads
          • The forum ‘Cloverleaf’ is closed to new topics and replies.