Hi all!
I've been brooding about this one for some time now: I've got an array of strings with mixed data in it (alphanumerical, punctuation, whitespace). The strings are of variable length. I need to sort that data, but any numbers that show up in the data have to be taken into account. Tcl seems to have such a sort function, and the "lsort -dictionary" man page describes what I'm looking for better than I could...
Use dictionary-style comparison. This is the same as -ascii except (a) case is ignored except as a tie-breaker and (b) if two strings contain embedded numbers, the numbers compare as integers, not characters. For example, in -dictionary mode, bigBoy sorts between bigbang and bigboy, and x10y sorts between x9y and x11y.
I've been rummaging through the archives of "Seekers of Perl Wisdom" as well as Q&A and Google, but all I was able to find were alphabetical sorts (i.e. ignoring case and whitespace).
From what I've seen, the whole problem seems to boil down to finding the right string comparison (which could then be used in sort) - or is that already the wrong approach?

If anyone out there has a solution for this or could at least point me in the right direction, I'd be very grateful...

argathin

In reply to Dictionary-style sort a la Tcl? by argathin

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.