Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Create union from ranges, but compare respectively

by GrandFather (Saint)
on Jun 10, 2022 at 01:49 UTC ( [id://11144633]=note: print w/replies, xml ) Need Help??


in reply to Create union from ranges, but compare respectively

Strictures are your friend (use strict; use warnings; - see The strictures, according to Seuss). In this case forcing you to declare variables with my may have made you think about the scope of $u_set and that may have led you to realize that the print is in the wrong place, and that may have led you to realize that the for loop was only performing one iteration, and that may have led you to notice that you used a tab character to split on instead of a comma. A better version of the code might look like:

use strict; use warnings; 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); for my $i (0 .. $#split_TM1) { my $set1 = Set::IntSpan->new($split_TM1[$i]); my $set2 = Set::IntSpan->new($split_TM2[$i]); my $u_set = intersect $set1 $set2; print "Union of strings: $u_set\n"; }

Note the Perlish for loop and avoidance of object indirect calling of the Set::IntSpan constructor.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found