Difference between set and append

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Difference between set and append

  • Creator
    Topic
  • #47618
    David Teh
    Participant

      Hi folks,

      Is there a difference between the below:

      #1

      set finalmsgf [concat $mshsr$PIDsegmentallr$PV1segmentallr$restmsgr]

      #2

      set finalmsg1 [concat $mshsr$PIDsegmentallr$PV1segmentallr$restmsg]

      append finalmsgf “$finalmsg1r”

      The above is the only difference between 2 tclprocs that I am testing.

      Oddly, the output of #1 is missing the x0d at the end of message.

      Any ideas?

      TIA!

    Viewing 6 reply threads
    • Author
      Replies
      • #56279
        James Cobane
        Participant

          The concat command is used to join “lists” together; the append command is used to join values to a variable.  So, depending on what your desired result is, you need to use the appropriate command.

        • #56280
          David Teh
          Participant

            Just curious, in this case:

            set finalmsgf [concat $mshsr$PIDsegmentallr$PV1segmentallr$restmsgr]

            would that last ‘r’ be ‘added’ to finalmsgf, or left out?

            TIA!

          • #56281
            David Teh
            Participant

              Ok, just to answer my last question…

              set finalmsgf [concat $mshsr$PIDsegmentallr$PV1segmentallr$restmsgr]

              That last statement won’t work.

              We would need to do something like this:

              set finalmsgf [concat $mshsr$PIDsegmentallr$PV1segmentallr$restmsg]

              append finalmsgf “r”

              Thanks folks!

            • #56282
              James Cobane
              Participant

                A solution would be:

                set finalmsgf [join “$mshs $PIDsegmentall $PV1segmentall $restmsg” r]

                where “$mshs $PIDsegmentall $PV1segmentall $restmsg” is a list and the ‘join’ command creates a single element from the list with a r between each of the original list elements.

              • #56283
                Robert Milfajt
                Participant

                  A couple of things.  The method James suggested,

                  set finalmsgf [join “$mshs $PIDsegmentall $PV1segmentall $restmsg” r]

                  leaves off the trailing r and strips out the from the MSH segment, at least in my testing using hcitcl.  I’m guessing the latter is a result of the fact that is an escape character.

                  For Dave’s dillemma, I’m not sure why the r is not being included with the concat command, but if you use the cconcat command, which I tried, you do get the r at the end of the result.

                  Both

                  set finalmsgf [cconcat $mshsr$PIDsegmentallr$PV1segmentallr$restmsgr]

                  and

                  set finalmsgf [cconcat $mshs “r” $PIDsegmentall  “r” $PV1segmentall “r” $restmsg”r”]

                  Gave the final message with trailing x0d character.

                  The only difference I could see regarding concat and cconcat in the help was that concat will eliminate any leading or trailing spaces.  Perhaps its treating the final “r” as white space and eliminating it.

                  Hope this helps.

                  Bob

                  Robert Milfajt
                  Northwestern Medicine
                  Chicago, IL

                • #56284
                  Nathan Martin
                  Participant

                    I noticed a few examples in this thread that appear to be mixing lists and strings.

                  • #56285
                    David Teh
                    Participant

                      Hi folks,

                      BIG THANKS!

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