Generally I use an extra array for extracted keys and then use it to sort indices.
my @sorted = do { my @key = map { lc substr $_->[ 4 ], 0, 3 } @a_of_a; my @idx = sort { $key[ $a ] cmp $key[ $b ] } 0 .. $#key; @a_of_a[ @idx ]; };
That’s much easier to follow than the ST. Additionally, it uses orders of magnitude less memory for large datasets because it doesn’t create zillions of tiny anonymous arrays. (I love Perl’s effortless data structures and what they enable, I really do, but roughly 100 bytes of overhead for an empty array… talk about wasteful.) It’s also faster for the same reason. In fact, it’s a speed demon – as fast as it gets without a GRT, or possibly faster if the transform you need for your GRT is costly.
What’s not to like? I see very little reason to use a classic ST.
Makeshifts last the longest.
In reply to Better sorting than the ST (was: Perl is dying)
by Aristotle
in thread Perl is dying
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |