Based on corrected BrowserUk's (++) code, I offer:
This version tracks the deleted item ID's.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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |