http://www.perlmonks.org?node_id=1060384


in reply to Calculate the overlap length between two ranges

Two ranges A and B overlap if low(A) <= high(B) AND high(A) >= low(B) ... hope I got that right, but it’s something like that.   Yes, there should be a CPAN module as-noted which does this simple task and probably others that will be of interest to you.

Then, again IIRC, the distance ought to be something like Max(Low(A), High(B)) - Min(Low(B), High(A)) ... not so sure about that one, it’s been a while.   Anyway, I do remember that you are testing the opposite-end numbers in each pair in some way.

Replies are listed 'Best First'.
Re^2: Calculate the overlap length between two ranges
by Laurent_R (Canon) on Oct 30, 2013 at 18:04 UTC

    Except that the OP did not speak about distance but about "the length between some overlapping numerical ranges", this phrasing does not really make sense to me. The length between overlapping ranges, if anything, is 0. This is why I kindly asked for clarification. Or, perhaps, it is a deficiency in my command of the English language. But the OP answered some later posts by other monks, but did not see it fit to answer mine.