It looks like your strings are comma-separated, but you are splitting them on tabs. You are also overwriting $u_set each time round the loop, so you'll need to accumulate the result differently.
I'd probably aim to write it something like this:
use strict; # always use warnings; # always use Set::IntSpan; my $TM_part1 = "25-40,74-93,95-120,130-149"; my $TM_part2 = "31-47,84-99,107-123,137-151"; my @split_TM1 = split ',', $TM_part1; my @split_TM2 = split ',', $TM_part2; my $u_set = join ',', map { my $set1 = Set::IntSpan->new($split_TM1[$_]); my $set2 = Set::IntSpan->new($split_TM2[$_]); intersect $set1 $set2; } 0 .. $#split_TM1; print "Union of strings: $u_set\n";
.. but if you're not comfortable with map, you can accumulate the results in an array instead:
use strict; # always use warnings; # always use Set::IntSpan; my $TM_part1 = "25-40,74-93,95-120,130-149"; my $TM_part2 = "31-47,84-99,107-123,137-151"; my @split_TM1 = split ',', $TM_part1; my @split_TM2 = split ',', $TM_part2; my @u_set; for my $i (0 .. $#split_TM1) { my $set1 = Set::IntSpan->new($split_TM1[$i]); my $set2 = Set::IntSpan->new($split_TM2[$i]); push @u_set, intersect $set1 $set2; } my $u_set = join ',', @u_set; print "Union of strings: $u_set\n";
In reply to Re: Create union from ranges, but compare respectively
by hv
in thread Create union from ranges, but compare respectively
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |