in reply to Re: alphabetize a hash ignoring upper/lower cases
in thread alphabetize a hash ignoring upper/lower cases

For very small hashes, performing two lc(...$a...) calls per sort iteration is okay.

For larger hashes, performing all those calls per sort iteration will bog you down. As the number of items increases, the number of sorting comparison increases geometrically. If you need speed, look around for the "Schwartzian Transform" (named after our own merlyn).

my @ordered = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, expensive_function($_) ] } # such as lc() @unordered; # such as keys %hash

This calls an expensive setup operation once per item and saves the resulting value, then sorts according to these temporary values, then strips away the temporary values, leaving the original items, but in the right order.

[ e d @ h a l l e y . c c ]