Hi, I have three ints describing locations which I read to a hash data structure:

$VAR1 = { '27069_1' => { 'stop' => 214601666, 'start' => 214600991 }, '14644_1' => { 'stop' => 166950686, 'start' => 166950125 }, }

I'd need to remove the elements that have equal start/stop locations the ones that have lt start comparing to other but the stop will be between second elements start and stop. And if the second elements start is between the first elements start and stop and the stop is gt than the first elements stop. I know this is really hard to explain. I try to achieve this by creating the not that complex data structure with:

$tss{$ch[0]}{$id}={ start=>$start, stop=>$stop };

For some reason it manages to remove 'some' elements that have overlapping region in somehow but not all. The removing is done in:

for(keys(%the_hash)){ my $ch=$_; my @a=keys(%{$tss{$ch}}); my $tid=pop(@a); my $s=$tss{$ch}{$tid}{'start'}; my $st=$tss{$ch}{$tid}{'stop'}; foreach(keys(%{$tss{$ch}})){my $k=$_; if($tss{$ch}{$k}{'start'} eq $s and $tss{$ch}{$k}{'sto +p'} eq $st #and $_ ne $tid ){ delete($tss{$ch}{$k}); } ..... and so on

The loop is quite long having just more elif-statements to see if the regions overlap. I think the problem lies somewhere in the looping technique I'm using. I tried others but with no succes. Also I could change the data structure. Now it is having a hash, which has like 20 numeric keys, and each of those having multiple different id's (unique keys) and each id has the start and stop property. I try to access first for each of the 20 first elements as the id's can be groupd due that to smaller groups.


In reply to 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.