It may be easier to read, manage and extend this, if it is written in OO style.

Based on corrected BrowserUk's (++) code, I offer:

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}?@{$sel +f->{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;
This version tracks the deleted item ID's.

             I hope life isn't a big joke, because I don't get it.
                   -SNL


In reply to Re: deleting elements in nested hash structure by NetWallah
in thread deleting elements in nested hash structure by lshadow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.