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

    Thank you hdb for your reply.

    Very clever! One liners never cease to amaze me. I do have more checks, but in reference to my reply to LaurentR, I wanted to see if there is a way to look up multiple hash keys in one step.

    Thank you