>>>>> "Clinton" == Clinton A Pierce <[EMAIL PROTECTED]> writes:

Clinton>        @dummy=sort {
Clinton>                $r=$a cmp $b;
Clinton>                if ($r < 0) {
Clinton>                        ($a,$b)=($b,$a);
Clinton>                        $r=1;
Clinton>                }
Clinton>                $r;
Clinton>                } @list;
Clinton>        # Is @list sorted?  Not quite...

Clinton> Except this doesn't work.  Oh, $a and $b get modified and they're swapped
Clinton> at appropriate times, but the resulting mess in @list can hardly be called
Clinton> proper ordering.

For this to work, the element indirected by $a would have to always be
to the left of the element indirected by $b, and that's probably not
true.  In fact, we can see this:

@dummy = sort {
  print "$a $b\n";
  $a <=> $b;
} 1..9;

4 5
5 6
3 5
2 5
1 5
5 7
5 8
5 9
7 6
8 7
9 8
2 1
3 2
4 3

See the last few?  If you were to swap the 4/3 pair to put them
in order, you're actually taking them *out* of order.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Reply via email to