in reply to short sorts

return $sorts{$type}->($a,$b) if $type; my $random_sort = (keys %sorts)[rand (keys %sorts)]; return $sorts{$random_sort}->($a,$b) if !$type;
The last condition is not needed here: if you can get to the line, $type must be false. Otherwise, you would have returned already.

Replies are listed 'Best First'.
Re^2: short sorts
by Lady_Aleena (Priest) on Mar 30, 2012 at 17:23 UTC

    Thank you for pointing that out to me. I changed the last lines of the subroutine to include tobyink's suggestion of croak above in Re: short sorts. So now I have a more explicit conditional just to keep things tidy. Thanks! :)

    if ($type) { croak "$type is not supported" if !exists $sorts{$type}; return $sorts{$type}->($a,$b); } else { my $random_sort = (keys %sorts)[rand (keys %sorts)]; return $sorts{$random_sort}->($a,$b); }

    Update

    Since the random sort is not acting as I expected, I decided to just let the subroutine die there.

    if ($type) { croak "$type is not supported" if !exists $sorts{$type}; return $sorts{$type}->($a,$b); } else { die "A sort type was not selected."; }
    Have a cookie and a very nice day!
    Lady Aleena