in reply to Request help on optimizing a loop for looking up numbers
As a start have a look at this:
use strict; use warnings; my %conns; while(<DATA>){ $conns{$1} = $2 if /(\d+)-(\d+)/ and $2 > ($conns{$1}//0); } printf "%d:\t%d\n", $_, $conns{$_} for sort keys %conns; __DATA__ 4-12 7-10 7-12 8-13
Basically, for each start of interval you store the biggest end of interval. It is not clear to me whether you want to check for other, more comprehensive types of overlaps.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Request help on optimizing a loop for looking up numbers
by VincentK (Beadle) on Dec 11, 2013 at 16:33 UTC |