【发布时间】:2014-07-18 20:50:29
【问题描述】:
大家早上好,我需要一些帮助...
我有这样的代码和平:
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";
}
}
}
}
}
}
}
你可以看到,我有两条打印线。一行打印到屏幕,另一行打印到文件。但是,该文件仍然是空的。为什么?我以正确的方式打开文件...
你知道这里发生了什么吗?
提前致谢。
【问题讨论】:
-
您是在程序运行且句柄仍处于打开状态时查看文件,还是在完成后查看文件?
-
tee可用于将 STDOUT 克隆到文件,而无需在脚本中处理文件,例如perl your_script.pl | tee results_BLAST_adjacentgenes_samehit.txt
标签: perl