A tcl Challenge

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf A tcl Challenge

  • Creator
    Topic
  • #52345
    Bob Moriarty
    Participant

      5.6.2 on RedHat.

      I am scratching my head over an in-line one-liner in an Xlate.

      Works fine from the tcl prompt – to wit:

      Code:

      tcl>echo $x
      123 / qwe
      tcl>set z [string range $x 0 [expr [string first / $x] – 1]]
      123


      However, within an Xlate I see the following error:

      Quote:

      QDX_Tcl_SplitList({20000 Units ) failed: unmatched open brace in list

      (xlateInVals = 20000 Units / 200 mL) <-- not part of error message In-line code:

      Code:

      set xlateOutVals [string range $xlateInVals 0 [expr [string first / $xlateInVals] – 1]]

      This sort of problem makes me feel young again.   😳

    Viewing 0 reply threads
    • Author
      Replies
      • #73880
        Jim Kosloskey
        Participant

          Bob,

          xlateInVals and xlateOutVals are lists and you need to treat them that way.

          You can use lndex on xlateInVals and that will resolve the problem you are experiencing but I would also use something like lreplace on xlateOutVals or otherwise you might see improperly structured output.

          Basically the issu is that what xlateInVals really contains is “{20000 Units / 200 mL}” because it is a list. When you treat that as a tring, the string range retrieves the leading curly brace as the first character and then that appears as an unclosed brace firther in.

          Still using list notation, you could also use the split command maybe along with the string trim command to get rid of unwanted leading or trailing spaces.

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

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