Hi Monks,

I have some rangers of numbers, and I want to find their union, BUT only comparing them pair-wise. Example:

25-40,74-93,99-120,130-149 31-47,84-99,107-123,137-151

My code:
use Set::IntSpan; $TM_part1="25-40,74-93,95-120,130-149"; $TM_part2="31-47,84-99,107-123,137-151"; @split_TM1 = split("\t", $TM_part1); @split_TM2 = split("\t", $TM_part2); for ($i=0; $i<=$#split_TM1; $i++) { $tm_range1 = $split_TM1[$i]; $tm_range2 = $split_TM2[$i]; $set1 = new Set::IntSpan $tm_range1; $set2 = new Set::IntSpan $tm_range2; $u_set = intersect $set1 $set2; } print "Union of strings:".$u_set."\n";
Output: 31-40,84-93,95-99,107-120,137-149 Problem here is that I get an extra one, i.e. 95-99, because the 3rd range of $set1 partially overlaps with the 2nd range of $set2. Is there a way to tell my script to only create union of strings in a pairwise manner? Like compare 1st range of $set1 to 1st range of $set2, create the union of these two, then proceed to create the union between the 2nd range of $set1 and 2nd range of $set2 etc.
Note: the number of ranges is always the same between $set1 and $set2.

In reply to Create union from ranges, but compare respectively by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.