+ -
当前位置:首页 → 问答吧 → 关于perl输出到文本的一个诡异问题

关于perl输出到文本的一个诡异问题

时间:2011-03-24

来源:互联网

现在我打算读入一个文本文件,然后存到数组里面去,进行一定修改以后存到另外一个文本里面去。我用了printf,整个内容都转过去了没错,但是一直有warning,
use of uninitialized value.

大家帮忙看看咋回事呢。谢谢!

#!/usr/bin/env perl -w
use strict;

open (FILE,"$ARGV[0]") or die "error in opening file $!\n";
my @output = <FILE>;
close FILE;

open (FILE, ">test.out1") or die "error in opening file $!\n";
for (my $i=0; $i<@output; $i++){
printf FILE $output[$i];
}

最初的文本文件大概是这样的:
# BLASTN 2.2.20 [Feb-08-2009]
# Query: FBO9Y7B01ARQHR
# Database: Geranium_palmatum
# Fields: Query id, Subject id, 0dentity, alignment length, mismatches, gap openings, q. start, q. end, s. start, s. end, e-value, bit score
FBO9Y7B01ARQHR Geranium_palmatum: 100.00 92 0 0 21 112 124834 124925 7e-48 182
# BLASTN 2.2.20 [Feb-08-2009]
# Query: FBO9Y7B01AI4KO
# Database: Geranium_palmatum
# Fields: Query id, Subject id, 0dentity, alignment length, mismatches, gap openings, q. start, q. end, s. start, s. end, e-value, bit score
FBO9Y7B01AI4KO Geranium_palmatum: 96.97 99 0 3 13 111 124293 124198 1e-37 149
# BLASTN 2.2.20 [Feb-08-2009]
# Query: FBO9Y7B01ANXUE
# Database: Geranium_palmatum
# Fields: Query id, Subject id, 0dentity, alignment length, mismatches, gap openings, q. start, q. end, s. start, s. end, e-value, bit score
FBO9Y7B01ANXUE gene:rps8_42661_43065_Geranium_palmatum: 99.25 134 0 1 15 147 232 99 3e-68 250
FBO9Y7B01ANXUE Geranium_palmatum: 99.25 134 0 1 15 147 42892 42759 3e-68 250

local multiple blast的输出结果,基本上是一个query一个warning。

作者: mooncake2010   发布时间: 2011-03-24

补充一下,问题出在第四行# Fields: Query id, Subject id, 0dentity, alignment length, mismatches, gap openings, q. start, q. end, s. start, s. end, e-value, bit score

printf输出的时候会同时报错,uninitialized value...

作者: mooncake2010   发布时间: 2011-03-24

大概知道是什么问题了,第四行里面有个%,perl printf的时候把这个%当成格式符号了,但是后面又么有数字跟着,所以他就报错了,输出到文本变成一个0,大家知道这种问题怎么解决吗?

作者: mooncake2010   发布时间: 2011-03-24