On 8/14/07, Wagner, David --- Senior Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote: > I am attempting to sort data which has a combination of both numeric > and alpah numeric data. Now it would not be so bad, but the numeric data > can be either 9 or 10 characters in length and no leading zero is > supplied in the numbers. > > I have supplied some code I am playing with, but running into a mental > block in attempting to get it sorted. > > Any thoughts on how to approach would be greatly appreciated?
A few things first: 1) your sample data does seem to supply leading zeros. 2) You haven't told us the relative value of letters vs. numbers. I'll assume you want numbers to sort lower than alphas and that your test data isn't representative. That said, your logic will look something like this: return -1 if $a is numeric and $b is alpha return 1 if $a is alpha and $b is numeric return $a <=> $b if both are numeric return $a cmp $b if both are alpha something like the following should work: sort { return $a =~ /\D/ ? ( $b =~ /\D/ ? $a cmp $b : 1 ) : ( $b =~ /\D/ ? -1 : $a <=> $b ) ; } HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!