In computer programming, the Schwartzian transform is a technique used to improve the efficiency of sorting a list of items.
The Schwartzian transform is a version of a Lisp idiom known as decorate-sort-undecorate, which avoids recomputing the sort keys by temporarily associating them with the input items.
Reading from right to left (or from the bottom to the top): The use of anonymous arrays ensures that memory will be reclaimed by the Perl garbage collector immediately after the sorting is done.
Without the Schwartzian transform, the sorting in the example above would be written in Perl like this: While it is shorter to code, the naive approach here could be much less efficient if the key function (called foo in the example above) is expensive to compute.
The following example pseudo-code implements the algorithm in this way: The first known online appearance of the Schwartzian transform is a December 16, 1994 posting by Randal Schwartz to a thread in comp.unix.shell Usenet newsgroup, crossposted to comp.lang.perl.