Bakken, Luke wrote:
> JupiterHost.Net wrote:
>>>On Oct 3, JupiterHost.Net said:
>>>
>>>>I have a list of strings that start with an uppercase B, Q, or Z
>>>>
>>>>I need to sort them so they are in order of Q, B , then Z
>>>>
>>>>Any ideas or input on how to efficiently do that with sort() or even
>>>>map() is most appreciated :) perldoc -f sort|-f map didn't appear to
>>>>address this situation :(
>>Jeff 'japhy' Pinyan wrote:
>>
>>>I would use map() before and after sort() to "correct" leading
>>>characters. 
>>>
>>>  my @sorted =
>>>    map { tr/123/QBZ/; $_ }
>>>    sort
>>>    map { tr/QBZ/123/; $_ }
>>>    @data;
>>
>>Brilliant! I'll benchmark those ideas :) Thanks you two!
> 
> Read this for an explanation of Jeff's solution:
> 
> http://en.wikipedia.org/wiki/Schwartzian_transform

Actually Jeff's solution uses the Guttman-Rosler transform:

http://www.sysarch.com/Perl/sort_paper.html



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to