tcl sort

  • Creator
    Topic
  • #53985
    Paul Sullivan
    Participant

      Hopefully a simple tcl question. We have up to seven alpha characters stored in a single variable. We need to sort the variable A-Z to limit the choices that are in a table. My tcl is weak.

    Viewing 4 reply threads
    • Author
      Replies
      • #79765
        Keith McLeod
        Participant

          Can you elaborate with an example?

        • #79766
          James Cobane
          Participant

            Paul,

            I’m not sure I fully understand your question, but I will assume that you have a variable (myvar) whose value is “A D B F C E”.  If so, you could simply make it a list and then sort the list; i.e.

            set mylist [split $myvar]

            set myvar [lsort $mylist]

            Hope this helps.

            Jim Cobane

            Henry Ford Health

          • #79767

            Yup, the tcl lsort command is what you need.

            http://www.tcl.tk/man/tcl8.4/TclCmd/lsort.htm

            On Unix or Linux, you can also use the system sort command by calling it with the tcl exec command.

            set var1 [exec sort $fileName]

            Read the sort man pages for all of the options.

            -- Max Drown (Infor)

          • #79768
            Charlie Bursell
            Participant

              Of course before you use lsort your variable must be turned into a list.

              Try this .. not pretty but works

              set X CBFADE

              set Y [join [lsort [split $X “”]] “”]

              => ABCDEF

            • #79769
              Paul Sullivan
              Participant

                Appreciate the replies and I will practice with this bit of tcl, but I did not really think my issue through well enough. Turns out there may be 1000+ combinations to choose from. Not something I wish to maintain a table for. I went the hard code route and is running OK.

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