Good morning to everyone, I need some help with this...
I have this peace of code:
open $fh, ">", "./results_BLAST_adjacentgenes_samehit.txt" or die "Could not write the file.";
print "Validating...\n";
$counter = 0;
for $key (keys %hash4000) {
for $hit1 (@{$hash4000{$key}}) {
for $hit2 (@{$hash4000{$key}}) {
$text = $hit1."\t".$hit2."\t".$key."\n";
next if $text ~~ @array; push @array, $text;
if ($chromosome{$transc{$hit1}} eq $chromosome{$transc{$hit2}} and $transc{$hit1} ne $transc{$hit2}) {
@sorted_startshit1 = sort { $a <=> $b } @{$starts{$transc{$hit1}}};
@sorted_startshit2 = sort { $a <=> $b } @{$starts{$transc{$hit2}}};
@sorted_endshit1 = sort { $b <=> $a } @{$ends{$transc{$hit1}}};
@sorted_endshit2 = sort { $b <=> $a } @{$ends{$transc{$hit2}}};
$start_hit1 = $sorted_startshit1[0];
$start_hit2 = $sorted_startshit2[0];
$end_hit1 = $sorted_endshit1[0];
$end_hit2 = $sorted_endshit2[0];
$dist1 = $end_hit1 - $start_hit2;
$dist2 = $start_hit1 - $end_hit2;
$strand_hit1 = $strand{$transc{$hit1}};
$strand_hit2 = $strand{$transc{$hit2}};
if (($dist1 < 10000 and $dist1 > 0) or $dist2 < 10000 and $dist2 > 0) {
if ($strand_hit1 eq $strand_hit2) {
$hit1 =~ /TCONS_([0-9]*)/;
$code_hit1 = $1;
$hit2 =~ /TCONS_([0-9]*)/;
$code_hit2 = $1;
$substract = $code_hit1 - $code_hit2;
if ($substract == 1 or $substract == -1) {
$counter++;
print $fh $counter."\t".$hit1."\t".$hit2."\t".$key."\n";
print $counter."\t".$hit1."\t".$hit2."\t".$key."\n";
}
}
}
}
}
}
}
You can see, I have two print lines. One line prints to the screen and the other one prints to a file. However, the file remains empty. Why? I open the file in a correct way...
Do you have any idea what's happening here?
Thanks in advance.