G'day vrk,

"Besides, Unicode codepoints often aren't ordered alphabetically in any script, so you wouldn't get a sorted (collated) sequence even if it did."

[Note: There's no intended pedantry here; however, as I understand your statement, I believe you mean "characters", not "codepoints". On that basis, I don't disagree with your statement, at all. The distinction is important for the remainder of my response.]

The builtin module Unicode::Collate can be used for sorting Unicode characters.

$ perl -E 'say for sort qw{z é a}' a z é $ perl -MUnicode::Collate -E 'say for Unicode::Collate::->new->sort(qw +{z é a})' a é z

The code points are numerical values: a numerical sort is required for these.

$ perl -E 'say for sort map { ord } qw{z é a}' 122 195 97 $ perl -E 'say for sort { $a <=> $b } map { ord } qw{z é a}' 97 122 195

Code points are often presented as hexidecimal strings (that may have a leading "U+"). When dealing with these, it can be useful to first convert them to some canonical format. As the code point range is 0 .. 0x10ffff, an sprintf format including "%06x" or "%06X" handles all cases.

$ perl -E 'say sprintf "U+%06X", $_ for map { ord } qw{z é a}' U+00007A U+0000C3 U+000061

— Ken


In reply to Re^2: Using "negative" characters with the range operator. [Unicode::Collate] by kcott
in thread Using "negative" characters with the range operator. by Bowlslaw

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.