good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Array Sortby anonymized user 468275 (Curate) |
on May 10, 2011 at 10:12 UTC ( [id://903945]=note: print w/replies, xml ) | Need Help?? |
An alternative optimising solution to the Schwartzian transform suggested by grandfather is the "Orcish Manoeuvre", which also ensures that the operation evaluating the sort key is only applied once per entry, while using the same hash overhead, but often slightly less processing:
BUT, in most cases, I tend to simply pass through the data once creating the inverse hash to that: Such a hash, using the key info as a hash key, tends to be more useful than a sorted array of keys in the subsequent processing. Note: if the middle field should vary in length, then the expression ( split /\-/ )[1] should replace the substr function. One world, one people
In Section
Seekers of Perl Wisdom
|
|