in reply to Calculate the overlap length between two ranges

Here’s a solution using Set::Scalar:

#! perl use strict; use warnings; use Set::Scalar; my $range1 = Set::Scalar->new(5 .. 25); my $range2 = Set::Scalar->new(7 .. 31); my $common = $range1->intersection($range2); my @members = $common->members(); print join(', ', sort { $a <=> $b } @members), "\n";

Output:

22:25 >perl 764_SoPW.pl 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 2 +5 22:25 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,