The Perl idiom Schwartzian transform



where foo($_) represents expression takes $_ (each item of list in turn) , produces corresponding value compared in stead.


reading right left (or bottom top):



the original list @unsorted fed map operation wraps each item (reference anonymous 2-element) array consisting of , calculated value determine sort order (list of item becomes list of [item, value]);
then list of lists produced map fed sort, sorts according values calculated (list of [item, value] ⇒ sorted list of [item, value]);
finally, map operation unwraps values (from anonymous array) used sorting, producing items of original list in sorted order (sorted list of [item, value] ⇒ sorted list of item).

the use of anonymous arrays ensures memory reclaimed perl garbage collector after sorting done.







Comments

Popular posts from this blog

Thenkalai and Vadakalai sub-traditions Sri Vaishnavism

Discography Pallas (band)

History Flexible-fuel vehicles in the United States