Schwartzian Sort

Randal L. Schwartz (1961-11-22+)

Back in the 1990s, working in Atari ST Basic I came up with a way to sort a table of records and fields where they are in a text file with special characters seperating the fields.

Name@Address#Phonenumber<19740729>
Where @, # and < seperate the fields.

Sorting by name is easy, just use the program function to do it.
But sorting by age is different, as the date begins at various locations.

To fix this was a three part process.

  1. Put the field to be sorted at the front.
  2. Sort the array
  3. Remove the front part

While I came up with this myself, I always assumed it was not original and probably dated back to the beginning of the computer age.

Turns out that this technique originated in the Perl programming community and was first described by Randal L. Schwartz in a December 16, 1994, Usenet post responding to a query about sorting filenames by their extension in the comp.unix.shell newsgroup. The name “Schwartzian transform” was coined by Bennett Todd in August 1995.

It is also known as ‘Decorate-Sort-Undecorate’

Leave a Reply