Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Sorting Data By Overlapping Intervals

by Eily (Hermit)
on Oct 31, 2013 at 21:39 UTC ( #1060649=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Sorting Data By Overlapping Intervals
in thread Sorting Data By Overlapping Intervals

Oh, right, I read an elsif instead of the second if, which meant that you would only have exited the loop when $position is above range. Then resetting $placeholder to 0 would work I guess (untested). But the condition is that your input data has to be sorted (as in ordered), which it seemed to be in your sample.

Still, you don't check that $placeholder is a valid value, if the last element of @SNP is inside one of the ranges, you'll increase $placeholder and try to access $SNP[last element+1] which would yield undef. I'm not sure you thought of that case.

In the end, your inner loop reworked would be something like :

# It would probably be better have # while (my $line = <CG>) # but that would mean rethinking your whole code for my $line (@SNP) { my $position = (split " ", $line)[3]; last unless $position <= $end; print OUT $line if $position > $start; }
This is of course, completely untested :D.


Comment on Re^3: Sorting Data By Overlapping Intervals
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-07-31 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (255 votes), past polls