Dan Laflamme wrote: > > I have a file that appears to be somewhat sorted, but is not sorted > according to the traditional unix sort. I'll give some examples, and if > anyone recgonizes the way in which the file is sorted, please let me > know. Also, since I may have to write a comparator function for use on > this "sorted" file, any tips on doing that in the most efficient way > possible would be helpful. Thanks. > > Examples. I give some sets of strings to indicate which comes before the > other in the "sorted" file. The first one in each pair is less than the > second. Each set is independent of the others. set x doesnt necessarily > come before set y in the file if x < y. > > Set 1: > 0-CELEBRITY-0 > 0-CELEBRITY > > Set 2: > 0-0-7 > 0-0 > > Set 3: > 000-AAA > 000 > > Set 4: > 000 > 0000 > > Set 5: > 0908 > 09088122595 > 09088122595 > 0909-114
We could make guesses as to the sort algorithm, but there is very little data here to go on. If you sort stringwise on the first fragment of the string up to the dash then you will get exactly this order. But several strings have the same first fragment (all of Set 1 and Set 2, for instance, start with the value '0'). Do you have access to the sort operation so that you can sort arbitrary data? This can be decided properly only by seeing how contrived test data is sorted. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>