arbitrary sorting...

Tkil tkil at
Thu Jul 18 18:40:11 CDT 2002

Last response to myself for a while, I hope.

>>>>> "Tkil" == tkil  <tkil at> writes:

Tkil> One way to avoid the reverse is to start with a higher score,
Tkil> and count down.  (Or start with zero and go negative -- same
Tkil> difference.)

I did this:

| my @foo_by_bar = do
| {
|     my $i = @bar;
|     my %s = map { $_ => --$i } @bar;
|     if (my @missing = grep !exists($s{$_}), @foo)
|     {
|         warn "not in bar: @missing";
|         foreach (@missing) { $s{$_} = ++$i; }
|     }
|     sort { $s{$a} <=> $s{$b} } @foo;
| };

Which sorted in the opposite order.  Giving bigger values to the
earlier members of @bar makes sense if they are "weights", but that
sort comparison function was expects "ranks".

Anyway, I suppose I could have just flipped the comparison, but I
ended up deciding that I'd just "score" from zero and sort in
ascending order.

Hope that makes more sense.


More information about the Pdx-pm-list mailing list