in reply to Re: adding the missing sequence numbers
in thread adding the missing sequence numbers

Also you seem to have duplicate keys in your hash

His hash never has more than one element, so I find that hard to believe.

  • Comment on Re^2: adding the missing sequence numbers

Replies are listed 'Best First'.
Re^3: adding the missing sequence numbers
by jethro (Monsignor) on Jan 19, 2011 at 19:16 UTC

    Let me rephrase that: Also you seem to try to store duplicate keys in your hash ;-)

    Naturally the 'my %hash' inside the loop prevents any data to accumulate in the hash (this as an explanation to the poster who started the thread), but I'm sure he had something else in mind for that hash. Not to say that I did spot that bug, I didn't

      hello this is my first post. I think third column has some special meaning which I don't know. If treat rows with each third column value, how about like this?
      use strict; use warnings; my @key=("key", "start", "end"); my @data=(); my $key_pre=0; while(<DATA>) { my %hash; @hash{@key}=(split(/,/,$_))[2 .. 4]; #(key=>1, start=>23, end=> +45) if ($key_pre != $hash{key} ){ &proc_eachkey( \@data ) if $#data > 0; @data=(); } $key_pre=$hash{key}; push @data, {%hash}; #copy hash value } &proc_eachkey( \@data ) if $#data > 0; #for last key sub proc_eachkey { my ($data)= @_; my ($start_pre, $end_pre)=(0,0); foreach my $h (@$data){ if ($end_pre != $h->{start} + 1) { printf "%d,%d,%d\n", $h->{key}, ($start_pre + 1), ($h->{s +tart} -1); } printf "%d,%d,%d\n", $h->{key}, $h->{start}, $h->{end}; ($start_pre, $end_pre)=($h->{start}, $h->{end}); } } __DATA__ 1,34,1,23,45,2,2 35,45,1,56,78,1,1 46,56,1,88,101,2,2 57,68,2,13,34,4,3 69,78,2,45,56,1,3
      nothing better than ikegami's one. regards.