<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Check overlaps with Perl]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/30930/check-overlaps-with-perl?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/30930/check-overlaps-with-perl?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/30930/check-overlaps-with-perl</guid>
	<pubDate>Wed, 15 Feb 2017 04:43:39 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/30930/check-overlaps-with-perl</link>
	<title><![CDATA[Check overlaps with Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl
use strict;
use warnings;

#For normal overlaps 

my ($lower, $upper) = (40, 100);

for my $num (17,42,99,111) {

    my $is_between = (sort {$a &lt;=&gt; $b} $lower, $upper, $num)[1] == $num;
    
    printf &quot;$num is%s between $lower and $upper\n&quot;, $is_between ? &quot;&quot; : &quot; not&quot;;
}


#For range to range overlaps

#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

my ($lower, $upper) = (40, 100);

for my $range ( [10,17],
                [30,71],
                [42,99],
                [83,120],
                [101,111] ) {

    my $is_within = [(sort {$a &lt;=&gt; $b} $lower, $upper, @$range)[1,2]] ~~ $range;
    
    printf &quot;[@$range] is%s within [$lower $upper]\n&quot;, $is_within ? &quot;&quot; : &quot; not&quot;;
}</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>