I have a data file and 4th column looks like below: Some examples
34899939-34899967
34899939-34899967:349055 54-34905559
34899939-34899967:349055 54-34905559:349055 60-34905574
I have to extract like below:
For the first line:
$start = 34899939
$end = 34899967
$block_size = 1
For the 2nd line:
$start = 34899939
$end = 34905559
$block_size = 2
$n1=34899939
$n2=34899967
$n3=34905554
$n4=34905559
For the 3rd line:
$start = 34899939
$end = 34905574
$block_size = 3
$n1=34899939
$n2=34899967
$n3=34905554
$n4=34905559
$n5=34905560
$n6=34905574
I am able to differentiate 1 block and 2 block depending upon : character and able to find the solution for the 3rd line as below:
But how do I generalise the numbers with : to generate the $n(i)? Thanks.
34899939-34899967
34899939-34899967:349055 54-34905559
34899939-34899967:349055 54-34905559:349055 60-34905574
I have to extract like below:
For the first line:
$start = 34899939
$end = 34899967
$block_size = 1
For the 2nd line:
$start = 34899939
$end = 34905559
$block_size = 2
$n1=34899939
$n2=34899967
$n3=34905554
$n4=34905559
For the 3rd line:
$start = 34899939
$end = 34905574
$block_size = 3
$n1=34899939
$n2=34899967
$n3=34905554
$n4=34905559
$n5=34905560
$n6=34905574
I am able to differentiate 1 block and 2 block depending upon : character and able to find the solution for the 3rd line as below:
Code:
sub special {
chomp $_;
my @v = split(/\s+/,$_);
if($v[3] =~ /\:/) {
$num1 = $`;
$num2 = $';
if($num1 =~ /\-/) {
$n1 = $`;
$n2 = $';
}
if($num2 =~ /\-/) {
$n3 = $`;
$n4 = $';
}
}
$start = $n1;
$end = $n4;
print "$n1 \t $n2 \t $n3 \t $n4 \n";
}
Comment