use strict; use warnings; use Data::Dump qw[ pp ]; #------------------------------------------ {package Event; sub new{ my ($class,@att) = @_; return bless {map {$_=>shift(@att)} qw|ID start stop|}, $class ; } sub Overlaps_with{ my ($self, $other)=@_; return 0 if $self->{start} > $other->{stop}; return 0 if $self->{stop} < $other->{start}; push @{$other->{OVERLAPS}}, $self->{ID},$self->{OVERLAPS}?@{$self->{OVERLAPS}}:(); return 1; } 1; }#---- End of Package Event ------------------ my %tss = map { my $s = int( rand 1000 ); $_ => Event::->new ($_, $s, $s + int (rand 200) ); } 1 .. 15; pp \%tss; my @ids = sort{ $a <=> $b } keys %tss; for my $first ( 0 .. $#ids ) { for my $second ( $first+1 .. $#ids ) { if ($tss{$ids[$first]}->Overlaps_with ($tss{$ids[$second]})){ ## print "Deleting $ids[$first]\n"; delete $tss{ $ids[$first] }; last; } } } my @x = sort {$a->{start} <=> $b->{start} } values %tss; pp \@x;