Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
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.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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Create union from ranges, but compare respectively
by GrandFather (Saint) on Jun 10, 2022 at 01:49 UTC | |
|
Re: Create union from ranges, but compare respectively
by tybalt89 (Monsignor) on Jun 10, 2022 at 02:51 UTC | |
|
Re: Create union from ranges, but compare respectively
by hv (Prior) on Jun 10, 2022 at 01:08 UTC | |
|
Re: Create union from ranges, but compare respectively
by kcott (Archbishop) on Jun 10, 2022 at 09:07 UTC | |
by erix (Prior) on Jun 10, 2022 at 11:13 UTC | |
by erix (Prior) on Jun 12, 2022 at 07:12 UTC | |
|
Re: Create union from ranges, but compare respectively -- oneliner
by Discipulus (Canon) on Jun 10, 2022 at 12:13 UTC |