note
AnomalousMonk
<blockquote><i><c>
# Decending numeric and descending alpha
...
pack 'Na4a*', -(0+$_), ~substr( $_, 1), $_
...
;;
0uvmu
0dvys
0cjlf
9klou
9ijei
8klfd
...
1imwi
1akkn
</C></I></BLOCKQUOTE>
<p>
I think you fixed a <c> -substr( $_, 1) </C> (- vice ~) that was there originally, but I was still puzzled by the sorting of 0 <i>before</I> 9 in an otherwise <i>descending</I> numeric sort. Looking at the bit fields in detail tells the tale: the <c> -(0+$_) </C> expression should be <c> ~(0+$_) </C> instead (in this particular case at least) to produce an effective descending numeric ordering from an actual ascending lexicographic sort.
</P>
<c>
>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
</C>
<c>
>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
</C>
<p>
Hmmm... This is trickier than it looks. And it looks kinda tricky. (And I don't say that my little fix is general.)
</P>
1021725
1021739