Using glob to simplify Tcl switch statements

I rediscovered a handy option in the switch statement of the Tcl language today. Consider the following (rather long-winded I admit) snippet that carries out certain actions for various similar type of values of the variable x.

switch $x {
typeA -
typeB -
typeC -
typeD { ;# Do something for all 4 types }
otherA -
otherB { ;# Do something else for all 2 others }
default { puts "Invalid Option: $x" }

Using the -glob parameter on the switch command in conjunction with the regular expression-like tweaks to the case conditions allows the entire construct to be simplified as follows:

switch -glob $x {
type[ABCD] { ;# Do something for all 4 types }
other[AB]  { ;# Do something else for all others }
default { puts "Invalid Option: $x" }

Useful tricks and tips for Geeks

I’ve encountered a number of SlashDot posts over the past week or so which discuss some of the more useful aspects of several computing tools that I use regularly. I’d commented on the first two individually (Forgotten Unix Tricks and Useful Vim Tricks) but since then, several more have emerged.

So, here are the links to each of them in one post, showing their original titles (not mine):

If someone (not me) were to make these into a book, I reckon it would prove to be quite popular. I know I’d certainly buy a copy.