This seems a little like cheating, but one way around the conflict would be to split your database lookup in twain:

select myid from mytable where myid rlike '^[A-Z].*' order by myid; select myid from mytable where myid rlike '^[0-9].*' order by abs(myid +);

Process them in that order, and you'll have your alpha ones ahead of your numerical ones, and both already sorted -- case-insensitive string sort on the first command, and numeric sort on the second. If you need to do any further sorting on either batch, it should be simpler. Also, letting the database engine order them should be faster than doing it in Perl after fetching them, especially if you put an index on the column in question.

Aaron B.
Available for small or large Perl jobs; see my home node.


In reply to Re: Sorting Numbers & Text by aaron_baugher
in thread Sorting Numbers & Text by PriNet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.