Set, Format problem

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Set, Format problem

  • Creator
    Topic
  • #52925
    Johnny Anderson
    Participant

      CL v5.8, HL7 v2.5.1, Sun, Solaris 10.

      I want a counter to look like this: 001, 002, 003, 004, etc.  Will be used as part of a filename.

      My code:

      set  filenamectr 001

      echo “@@@ 1st filenamectr: ” $filenamectr

      set  filenamectr [format “%03s” $filenamectr]

      incr filenamectr 001

      echo “@@@ 2nd filenamectr: ” $filenamectr

      Results:

      @@@ 1st filenamectr:  001

      @@@ 2nd filenamectr:  2

      Found examples on the forum and tcl guides.  One warned about math and octal.  What

    Viewing 3 reply threads
    • Author
      Replies
      • #75950
        Charlie Bursell
        Participant

          beginning zero is octal

          Do this:

          set  filenamectr 1

          set fmtnamectr [format “%03s” $filenamectr]

          echo “@@@ 1st filenamectr: ” $fmtnamectr

          incr filenamectr

          set fmtnamectr [format “%03s” $filenamectr]

          echo “@@@ 2nd filenamectr: ” $fmtnamectr

        • #75951
          Johnny Anderson
          Participant

            Charlie, made the change and reran.  Looks good until counter got to 008, then it quits with octal error.  See ppt attachment.

            The op files stop at 008:

            starlims_labrep_oru_switch_20120203134008_002.txt

            starlims_labrep_oru_switch_20120203134008_003.txt

            starlims_labrep_oru_switch_20120203134008_004.txt

            starlims_labrep_oru_switch_20120203134008_005.txt

            starlims_labrep_oru_switch_20120203134008_006.txt

            starlims_labrep_oru_switch_20120203134008_007.txt

            starlims_labrep_oru_switch_20120203134008_008.txt

            Searched forum, to fix octal it says to do

          • #75952
            James Cobane
            Participant

              You should keep your counter as a pure integer, and simply apply the “format” to it using a new variable to use within the filename:

              set

            • #75953
              Johnny Anderson
              Participant

                Thanks Jim, that did it.

                op files:

                starlims_labrep_oru_switch_20120203154031_001.txt

                starlims_labrep_oru_switch_20120203154031_002.txt

                starlims_labrep_oru_switch_20120203154031_003.txt

                starlims_labrep_oru_switch_20120203154031_004.txt

                starlims_labrep_oru_switch_20120203154031_005.txt

                starlims_labrep_oru_switch_20120203154031_006.txt

                starlims_labrep_oru_switch_20120203154031_007.txt

                starlims_labrep_oru_switch_20120203154031_008.txt

                starlims_labrep_oru_switch_20120203154031_009.txt

                starlims_labrep_oru_switch_20120203154031_010.txt

                starlims_labrep_oru_switch_20120203154031_011.txt

                starlims_labrep_oru_switch_20120203154031_012.txt

                starlims_labrep_oru_switch_20120203154031_013.txt

                starlims_labrep_oru_switch_20120203154031_014.txt

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