Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Calculate the overlap length between two ranges

by poolpi (Hermit)
on Oct 30, 2013 at 12:17 UTC ( #1060352=note: print w/replies, xml ) Need Help??


in reply to Calculate the overlap length between two ranges

Please have a look at this module Set::IntSpan.

#!/usr/bin/perl use strict; use warnings; use Set::IntSpan; my $set1 = new Set::IntSpan '31-52'; my $set2 = new Set::IntSpan '27-50'; my $u_set = intersect $set1 $set2; my @set = sets $u_set; print @set; __END__ output: 31-50

Update: code + typo


hth,
PooLpi

The stone that the builder refused, will always be the head cornerstone.
[ Robert Nesta MARLEY ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1060352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2023-02-05 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?