How can I do this in TCL?

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How can I do this in TCL?

  • Creator
    Topic
  • #51527
    Jeff Manley
    Participant

      I have a FT1 segment that looks like:

      FT1||73143|22578|20090824||CH|325005145||20863|1|116.50|116.50||||^^||||||170.35

      I want to copy the field 7 value to field 25 to look like this:

      FT1||73143|22578|20090824||CH|325005145||20863|1|116.50|116.50||||^^||||||170.35|||325005145

      I have the segment ripped apart, and I do have the value of field 7, but how do I add it to the segment in field 25?  I have tried lassign and lset and lappend.  Nothing seems to work right for me.

      Thanks.

    Viewing 1 reply thread
    • Author
      Replies
      • #70637
        Jerry Tilsley
        Participant

          If you have your segments and fields into a lists you can do this.

          Code:


                 lvarpop fields 25 $field7
          lvarpop segments $segIndex [join $fields $fsep]
                 set msg [join $segments r]
          msgset $mh $msg

          This way you put the value of field.7 into field.25, you put the new segment you have now into the list at the location of the old segment(before change), then you rebuild your message from the list of segments, lastly you set the new message to the message handle of the old message.  

          Now when you CONTINUE $mh, the new message will go.  Alternatively you could just create a new message handle and assign the new message to that handle and continue it and kill the original message handle, that’s up to you.

        • #70638
          Michael Hertel
          Participant

            Also for some commands, the field you are addressing needs to exist.

            i.e. your segment/list you are working on is 25 in length, you need to add the extra elements (two more to get to 27) before addressing them

            To make sure the list is long enough I do something like:

            set mylist [split $data[replicate $fsep 2] $fsep]

            The “$data[replicate $fsep 2]” part is the you want to tweak.

            Also of note, watch out for the sneaky $ when using list command.

            Some commands want the list value ($mylist) while other commands want the list name (mylist).

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