in reply to Re: Choosing "best" - sorting hashes issue
in thread Choosing "best" - sorting hashes issue

by_HoA_1_desc can be written more succinctly as
$myhash{$a}[1] <=> $myhash{$b}[1] || $myhash{$a}[0] <=> $myhash{$b}[0]

Dave.

Replies are listed 'Best First'.
Re^3: Choosing "best" - sorting hashes issue
by samizdat (Vicar) on Jan 17, 2005 at 14:35 UTC
    True. I'm still getting used to da spaceship. :)

    One question, how does it compare efficiency-wise to if-elseif chains?
Re^3: Choosing "best" - sorting hashes issue
by samizdat (Vicar) on Jan 17, 2005 at 14:57 UTC
    Ummm... in my case, since popularity is sorted in descending order and history needs to be sorted in ascending order, shouldn't it be:
    $myhash{$b}[1] <=> $myhash{$a}[1] || $myhash{$a}[0] <=> $myhash{$b}[0]
    ?

    In any event, thanks for suggesting the improvement. In my long-winded if-elsif chained version, I had one of the >'s reversed, leading to a very dirty bug.