in reply to find closest element of array without going over

If your array is always sorted, you can use a binary search to look for a value. That way you have only O(log(scalar @array)) lookup operations.

Basically you start in the middle of the array, compare your search value with the middle element, and if larger, search in the second half of the array. If smaller, search in the first half of the array.