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 same algorithm can be written procedurally to better illustrate how it works, but this requires using temporary arrays, and is not a Schwartzian transform.
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.