in reply to Re: List::BinarySearch and conditional tests with Test::More
in thread List::BinarySearch and conditional tests with Test::More

That should be...

$index = &List::BinarySearch::binsearch( sub {$a <=> $b}, 300, \@num_array, );

The difference from your original suggestion is that one should pass the array by reference.

Q: Why would the crazy author want the array parameter to be passed by reference? Doesn't he know this can be inconvenient? :) A: Because passing a list is an O(n) operation, whereas passing a reference is O(1). We wouldn't want the passing of parameters to have an order of growth that is worse than the order of growth of the underlying algorithm.

Of course you already know this, but it's worth mentioning in general.


Dave