Search code examples
sortingtclcase-insensitive

TCL 8.4 workaround for not having the lsort -nocase option?


I'm doing a simple TCL lsort using the -nocase flag. However, one system where I'm running that code is still using TCL 8.4, where the nocase isn't available. Is there any simple workaround, or will I have to manually handle this?


Solution

  • TCL 8.4 has the -dictionary flag, which provides case-insensitive comparisons. If your strings contain no digits on it, I think the behaviour is equal to the -nocase flag.

    From the documentation:

    -dictionary Use dictionary-style comparison. This is the same as -ascii except (a) case is ignored except as a tie-breaker and (b) if two strings contain embedded numbers, the numbers compare as integers, not characters. For example, in -dictionary mode, bigBoy sorts between bigbang and bigboy, and x10y sorts between x9y and x11y.

    -nocase Causes comparisons to be handled in a case-insensitive manner. Has no effect if combined with the -dictionary, -integer, or -real options.

    http://www.hume.com/html85/mann/lsort.html