On Oct 3, 2005, at 18:16, Jeff 'japhy' Pinyan 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 :(


I would use map() before and after sort() to "correct" leading characters.

  my @sorted =
    map { tr/123/QBZ/; $_ }
    sort
    map { tr/QBZ/123/; $_ }
    @data;

There's a potential gotcha there: since all Qs and Bs are being swapped lexicographic order after the first character is also changed. That might not be an issue though.

-- fxn

--
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