Help language development. Donate to The Perl Foundation

Numeric::Nearest cpan:DRCLAW last updated on 2019-02-27

Numeric-Nearest-0.5.1/

Numeric::Nearest

A simple module to find the nearest element in a ordered list without processing all elements.

The grep sub will process all elements in a list, which is slow when you have an ordered list of numbers.

Hashes only work for keys matching exaclty.

Example

use Numeric::Nearest;

my @l=1,2,3,4;

say nearestPair(1.2, @l);

The closest entry in the list to 1.2 is 1.

Details

Exported subs

sub nearestPair($key,$list,:$start);

Returns a pair of index => value of the element of $list which is nearest in magnitude to $key

sub nearestPairs($key,$list);

Returns a sequence of index => values, one for each element in the $keys variable.

License

Artistic-2.0