Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
# Decending numeric and descending alpha ... pack 'Na4a*', -(0+$_), ~substr( $_, 1), $_ ... ;; 0uvmu 0dvys 0cjlf 9klou 9ijei 8klfd ... 1imwi 1akkn

I think you fixed a  -substr( $_, 1) (- vice ~) that was there originally, but I was still puzzled by the sorting of 0 before 9 in an otherwise descending numeric sort. Looking at the bit fields in detail tells the tale: the  -(0+$_) expression should be  ~(0+$_) instead (in this particular case at least) to produce an effective descending numeric ordering from an actual ascending lexicographic sort.

>perl -wMstrict -le "print unpack 'H*', pack 'N', -0; print unpack 'H*', pack 'N', -1; print unpack 'H*', pack 'N', -2; print unpack 'H*', pack 'N', -9; print unpack 'H*', pack 'N', -10; print ''; ;; print unpack 'H*', pack 'N', ~0; print unpack 'H*', pack 'N', ~1; print unpack 'H*', pack 'N', ~2; print unpack 'H*', pack 'N', ~9; print unpack 'H*', pack 'N', ~10; " 00000000 ffffffff fffffffe fffffff7 fffffff6 ffffffff fffffffe fffffffd fffffff6 fffffff5
>perl -wMstrict -le "use List::Util qw(shuffle); ;; my @a = qw( 0uvmu 3rqhx 8klfd 2uwep 9klou 3jrkx 6excm 1imwi 7axqf 1lpys 0dvys 3ozcw 7lbhj 1pjzw 9ijei 3hiyn 3vkon 1akkn 0cjlf 3myrn ); ;; @a = shuffle @a; ;; print for map{ unpack 'x[Na4]a*', $_ } sort map{ local $^W; pack 'Na4a*', ~(0+$_), ~substr( $_, 1), $_ } @a " 9klou 9ijei 8klfd 7lbhj 7axqf 6excm 3vkon 3rqhx 3ozcw 3myrn 3jrkx 3hiyn 2uwep 1pjzw 1lpys 1imwi 1akkn 0uvmu 0dvys 0cjlf

Hmmm...     This is trickier than it looks. And it looks kinda tricky. (And I don't say that my little fix is general.)


In reply to Re^5: two order sort by AnomalousMonk
in thread two order sort by ag4ve

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 browsing the Monastery: (16)
    As of 2014-09-02 13:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (22 votes), past polls