Quoted Field caused tcl parse error – Why??

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Quoted Field caused tcl parse error – Why??

  • Creator
    Topic
  • #52598
    Tim Malaney
    Participant

      Quotes in a field caused a TCL error. Once the quotes were removed the tcl ran successfully. Just looking for the cause/reason the quotes caused the error. Any suggestion how to prevent it in the futute are appreciated

      Error

      result  = ‘list element in quotes followed by “|W|4915” instead of space’

             errorInfo: ‘

      list element in quotes followed by “|W|4915” instead of space

         while executing “lindex $segment 0”    (“foreach” body line 3)

      Field  

      PID|||99999999||ZZZZZ^ZZZZZ^ZZZZZ^^||99999999|F|PREFERS “PHYLLIS”|W|4915 SCHOEN R    

      TCL    

         set PIDfields [split $segment $fieldSep]

         set PIDfields [lreplace $PIDfields 4 4 00000]

         set PIDfields [lreplace $PIDfields 2 3 [lindex $PIDfields 3] “”]

         set PIDAcct [lindex $PIDfields 18]

         regsub -all {T} $PIDAcct {} NewPIDAcct

         set PIDfields [lreplace $PIDfields 18 18 $NewPIDAcct]

         set segment [join $PIDfields $fieldSep]

         set segmentList [lreplace $segmentList $i $i $segment]

      Thanks

      Tim

    Viewing 0 reply threads
    • Author
      Replies
      • #74808
        Levy Lazarre
        Participant

          Tim,

          It doesn’t show in the code fragment you submitted, but somewhere in your code, the following command was issued:

          Code:


          lindex $segment 0

          In other words, you are applying a list command (lindex) to a string ($segment). I am not sure if this is intentional or simply an overlook.

          Indeed, Tcl will allow you to treat a string as a list, but a space will be used as the default separator. The command failed on the PID segment because the separator suddenly changed from a space to a ‘|’ after the quoted element. You can easily test this at a Tcl prompt:

          % set mystring {This “is” a test.}

          % lindex $mystring 0   ===> This

          but

          % set mystring {This “is”|a test.}

          % lindex $mystring 0  ==> error: list element in quotes followed by “|a” instead of space

          To solve your problem, just replace the “lindex $segment 0” command with something else that achieves the intended result, perhaps a “split” command.

          I hope this helps.

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