TCL frag – lassign out to an unknown amount of variables

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL frag – lassign out to an unknown amount of variables

  • Creator
    Topic
  • #54731
    Lawrence Nelson
    Participant

      2 part question –

      Part 1

      Typically I have to break down a list into a set amount of variables with this kind of code –

      set xlateInVals [split $xlateInVals ;]

      lassign $xlateInVals var1a var1b var1c

      set xlateOutVals

        I need to work with an OBX that could have from 1 up to 150 or more items in the list.

        I figure I can do this the dirty way and just keep adding on $var1-150, but I have to believe there is a cleaner way to do that –

        Part 2

        Once those variable above are created I then need to be able to run those output variables through a table cleanly/concisely.

        Thanks

      Lawrence Nelson
      System Architect - MaineHealth IT

    Viewing 7 reply threads
    • Author
      Replies
      • #82754
        Brandon Grudt
        Participant

          What are you doing to the list items once you split them by a semicolon?

          Typically you would split the string like you had, and then perform a foreach.

            set count 0

        • #82755
          Lawrence Nelson
          Participant

            I’m looking to run each item through a table outputting to OBX:3

            Lawrence Nelson
            System Architect - MaineHealth IT

          • #82756
            Brandon Grudt
            Participant

              Then you’d use this:

              set editedvalue [tbllookup -side MY_SIDE MY_TABLENAME $value]

              (You’d substitute MY_SIDE with either input or output)

            • #82757
              Lawrence Nelson
              Participant

                That appears to be the answer to the Part 2 of my question – I’m thinking there should be a foreach somewhere in there for Part 1

                Lawrence Nelson
                System Architect - MaineHealth IT

              • #82758
                Lawrence Nelson
                Participant

                  Just to be clear – I want to use this in a Prec Proc area within an xlate –

                  set xlateOutVals1 [split $xlateInVals ;]

                  set $table Dominion_AOE_OBX

                  set $xlateOutVals [tbllookup -side input $table $xlateOutVals1]

                  Lawrence Nelson
                  System Architect - MaineHealth IT

                • #82759
                  Brandon Grudt
                  Participant

                    set count 0

                    set xlateInVals [split $xlateInVals ;]

                    foreach value $xlateInVals {

                  • #82760
                    Jim Kosloskey
                    Participant

                      The way we do this is:

                      Use a proc we have to split a field on a character into a list. That list is stored in an Xlate specified temp variable (like @mylist).

                      Then we use a list ITERATE as a while loop and inside that ITERATE we use another proc whiich pops off the top element of a list and returns that element plus the resultant list as 2 temp variables (like @myelem and @mylist).

                      Then we would do the Table Lookup using the Xlate TABLE action with @myelem being the source to lookup.

                      So we are just reusing already written code. We can then use the same 2 procs in any Xlate where the challengee is to make a list from a string and process the elements of the list using mostly Xlate Actions.

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

                    • #82761
                      Terry Kellum
                      Participant

                        Also, a basic point of potential error.

                        xlateInVals is a list.  In the script, you are handling it as a scalar.

                        This code will work when there is only one value being passed in.  If there are two, then it will fail in new, strange, and unfathomable ways.

                        If you expect to extract a scalar out of xlateInVals ALWAYS do a

                        set myvar [lindex $xlateInVals 0]

                        Out Vals is also a list.  If you do not remember this basic issue, you can look forward to a lot of fun 1 or 2 years down the line….

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