help array setting in tcl script causes other reading to fail.

Clovertech Forums Cloverleaf help array setting in tcl script causes other reading to fail.

Tagged: 

  • Creator
    Topic
  • #121934
    A Lim
    Participant

      Hi,

      Working on reading an xml file and convert it to HL7 before sending out through the socket using tcl script. As the amount of data within different xml section varies in each file – it could go from 0 to n number of values. So, the only way that I figure could accommodate such variation is using an array. However, implementing of the array proves to be challenging.

      The script that works fine as there is no array

                                  Rpt_SameRptOrder {
                                      switch -exact — $xmlTag {
                                          ExtNo{set sameExtNo $xmlData
                                               lappend debugLogMsg “ExtNo $sameExtNo”
                                          }
                                          OrderNo{set sameOrdNum $xmlData
                                               lappend debugLogMsg “OrdNo $sameOrdNum”
                                          }
                                      }
                                  }
                                  Rpt_2ndReqExam {
                                      switch -exact — $xmlTag {
                                          POS {set ExamPos $xmlData
                                                     lappend debugLogMsg “POS $ExamPOS”
                                          }
                                          CODE {set ExamCode $xmlData
                                                     lappend debugLogMsg “ExamCode $ExamCode”
                                          }
                                      }
                                  }
      When it reads the file, the values it will show as
           ExtNo 343434
           OrdNo 454354543
           ExtNo 65655
           OrdNo 565676765
           ExtNo 674543656
           OrdNo 665465654
           POS 1
           ExamCode XXX
           POS 2
           Exam Code YYY
      in the log. At the end, we only have
           ExtNo 674543656
           OrdNo 665465654
           POS 2
           Exam Code YYY
      available in the variables as it is not an array.

      If I switch to using array for the 1st part (Rpt_SameRptOrder) only

      set sameExtNo(Ord) 0

      set sameOrdNum(Ord) 0

                                  Rpt_SameRptOrder {
                                      switch -exact — $xmlTag {
                                          ExtNo {set i sameExtNo(Ord)
      set sameExtNo($i) $xmlData
      lappend debugLogMsg “$i ExtNo $sameExtNo($i)”
      incr sameExtNo(Ord)
      }
      OrderNo {set i sameOrdNum(Ord)
      set sameOrdNum($i) $xmlData
      lappend debugLogMsg “$i OrderNo $sameOrdNum($i)”
      incr sameOrdNum(Ord)
      }
      }
                                  }
                                  Rpt_2ndReqExam {
                                      switch -exact — $xmlTag {
                                          POS {set ExamPos $xmlData
                                                     lappend debugLogMsg “POS $ExamPOS”
                                          }
                                          CODE {set ExamCode $xmlData
                                                     lappend debugLogMsg “ExamCode $ExamCode”
                                          }
                                      }
                                  }
      When it reads the (same) file, the values it will show as
      ExtNo 343434
      OrdNo 454354543
      ExtNo 65655
      OrdNo 565676765
      ExtNo 674543656
      OrdNo 665465654
      in the log. At the end, we only have
      ExtNo 343434
      OrdNo 454354543
      ExtNo 65655
      OrdNo 565676765
      ExtNo 674543656
      OrdNo 665465654

      available. The script will not go into the Rpt_2ndReqExam section and get the following data

      POS 1
      ExamCode XXX
      POS 2
      Exam Code YYY
      It has to be something that I am not doing right, but I cannot figure out what is not right.
      • This topic was modified 1 week, 1 day ago by A Lim.
      • This topic was modified 1 week, 1 day ago by A Lim.
      • This topic was modified 1 week, 1 day ago by A Lim.
    • You must be logged in to reply to this topic.