Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

G'day Lady Aleena,

"I just can not come up with a list where this might be needed on alphabetical strings."

With split_sort(), as currently written, I can't see any use for the alpha sort type: it will return the same as a plain sort (in all cases, as far as I can tell).

With an alpha sort type ignoring case, you could get this difference:

$ perl -E 'my @x = ("ade:Y", "Abc:X", "Afg:Z"); say for sort @x' Abc:X Afg:Z ade:Y $ perl -E 'my @x = ("ade:Y", "Abc:X", "Afg:Z"); say for sort { fc($a) +cmp fc($b) } @x' Abc:X ade:Y Afg:Z

With an alpha sort type expecting Unicode, you could get this difference:

$ perl -C -E 'my @x = ("\x{c5}de:Y", "Abc:X", "Afg:Z"); say for sort @ +x' Abc:X Afg:Z Åde:Y $ perl -MUnicode::Collate -C -E 'my @x = ("\x{c5}de:Y", "Abc:X", "Afg: +Z"); say for Unicode::Collate->new->sort(@x)' Abc:X Åde:Y Afg:Z
"I am now thinking that I should just put a note in saying that the alphabetical usage is redundant."

Perhaps not entirely redundant. Consider its potential use in a scenario where you process an AoA which holds a mixture of numeric and alphabetic arrays.

my @multi_sorts = ( [ $array1, ':', 'num' ], [ $array2, '-', 'alpha' ], [ $array3, ',', 'num' ], ); handle_multi_mixed_sorts(\@multi_sorts); # At this point in the code, each of the arrays in @multi_sorts # has the original array still as the first element # and the sorted array now as the fourth element. sub handle_multi_mixed_sorts { my ($multi_sorts) = @_; for my $i (0 .. $#$multi_sorts) { push @{$multi_sorts->[$i]}, [ sort { split_sort($a, $b, $multi_sorts->[$i][1], $multi_sorts->[$i][2]) } @{$multi_sorts->[$i][0]} ]; } return; }

Do note that I just typed that code directly into my post: it's entirely untested.

— Ken


In reply to Re: Coming up with good examples in POD by kcott
in thread Coming up with good examples in POD by Lady_Aleena

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (9)
    As of 2021-01-27 20:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?