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.
|