in reply to deleting elements in nested hash structure
Something like this?
#! perl -slw use strict; use Data::Dump qw[ pp ]; my %tss = map { my $s = int( rand 1000 ); $_ => { start => $s, stop => $s + int( rand 100 ) } } 1 .. 100; #pp \%tss; my @ids = sort{ $a <=> $b } keys %tss; my @toDelete; for my $first ( 0 .. $#ids ) { for my $second ( $first+1 .. $#ids ) { ## updated per NetWallah's suggestion below push( @toDelete, $ids[ $first ] ), last unless $tss{ $ids[ $first ] }{ start } > $tss{ $ids[ $seco +nd ] }{ stop } or $tss{ $ids[ $first ] }{ stop } < $tss{ $ids[ $seco +nd ] }{ start }; } } #pp \@toDelete; delete @tss{ @toDelete }; pp \%tss; __END__ C:\test>junk { 74 => { start => 982, stop => 1011 }, 80 => { start => 572, stop => 577 }, 87 => { start => 286, stop => 319 }, 90 => { start => 600, stop => 674 }, 91 => { start => 252, stop => 266 }, 92 => { start => 1, stop => 7 }, 94 => { start => 210, stop => 221 }, 95 => { start => 553, stop => 554 }, 96 => { start => 113, stop => 158 }, 97 => { start => 752, stop => 820 }, 98 => { start => 543, stop => 550 }, 99 => { start => 436, stop => 456 }, 100 => { start => 696, stop => 725 }, }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: deleting elements in nested hash structure
by NetWallah (Canon) on Jun 02, 2012 at 17:31 UTC | |
by BrowserUk (Patriarch) on Jun 02, 2012 at 20:06 UTC | |
by NetWallah (Canon) on Jun 02, 2012 at 23:28 UTC | |
by BrowserUk (Patriarch) on Jun 02, 2012 at 23:37 UTC |