The stupid question is the question not asked | |
PerlMonks |
Re: Custom sort with string of numbersby Marshall (Canon) |
on Aug 29, 2010 at 06:16 UTC ( [id://857888]=note: print w/replies, xml ) | Need Help?? |
No need to get real fancy here.
The "Schwartzian Transform" is far less important that it used to be due to updated with better variable names in the sort. Names and code formatting do matter. Yet another comment: The idea behind the "Schwartzian Transform" is to calculate all this stuff like in the split's in one single pass thru the data and then use the resulting values for comparison in the sort. That idea being that we've saved all this calculation on a per pair comparison basis. The idea of the "Guttman-Rosler Transform" is to make a single string value that can be compared with a string comparison (cmp). I don't think that the OP needs either one. If you have a choice in formatting data like the OP's case, one way is to choose to add leading zeroes so that the normal cmp sort order "works out", this is the "Guttman-Rosler Transform" without any transformation! ie. @array = sort @array; works. If the set to be sorted is relatively small, the only thing that really matters is how clear the sort is. I think the above is very clear about what it does.
In Section
Seekers of Perl Wisdom
|
|