[求助] Use of uninitialized value

[求助] Use of uninitialized value

运行下面的代码提示说:

Use of uninitialized value $line in split at BLAST_result.pl line 25, <IN> line
3.
Use of uninitialized value $line in pattern match (m//) at BLAST_result.pl line
26, <IN> line 3.
Use of uninitialized value $line in pattern match (m//) at BLAST_result.pl line
26, <IN> line 3.
Use of uninitialized value $query_src in pattern match (m//) at BLAST_result.pl
line 39.
Use of uninitialized value $sbjct_src in pattern match (m//) at BLAST_result.pl
line 42.
Use of uninitialized value $query_src in pattern match (m//) at BLAST_result.pl
line 39.
Use of uninitialized value $sbjct_src in pattern match (m//) at BLAST_result.pl
line 42.
Use of uninitialized value $query_src in length at BLAST_result.pl line 50.
Use of uninitialized value in concatenation (.) or string at BLAST_result.pl lin
e 53.
Use of uninitialized value in concatenation (.) or string at BLAST_result.pl lin
e 53.
Use of uninitialized value $sbjct_src in length at BLAST_result.pl line 56.
Use of uninitialized value in concatenation (.) or string at BLAST_result.pl lin
e 58.
Use of uninitialized value in concatenation (.) or string at BLAST_result.pl lin
e 58.

不太明白这个使用未定义的初始值是什么意思? 还请各位指教,谢谢

代码如下:
#!/usr/bin/perl
use strict;
use warnings;

my $report_file = "report.txt";
my $blast_file = $ARGV[0] || 'blast.dat';
unless ( -e $blast_file) {
        die "$0: ERROR:missing file: $blast_file";
        }
       
my ($query_src, $sbjct_src,);
open (IN, $blast_file) or die "$0: ERROR: $blast_file: $!";
while (my $line = <IN>) {
        chomp $line;
        print "Processing line $.\n";
        }

my $line;
my @words = split /\s+/, $line;
if ($line =~ /^Query/) {
        $query_src .= $words[2];
        }
elsif ($line =~ /^Sbjct/) {
        $sbjct_src .= $words[2];
        }
       
close IN;

my @patterns = ('AGGAAC', '-');
my (%query_counts, %sbjct_counts);
foreach my $pattern (@patterns) {
        while ($query_src =~ /$pattern/g) {
                $query_counts{$pattern}++;
                }
        while ($sbjct_src =~ /$pattern/g) {
                $sbjct_counts{$pattern}++;
                }
        }
       

open (OUT, ">$report_file") or die "$0: ERROR: Can't write $report_file";
print OUT "Sequence report.\n", scalar localtime, "\n", "Total length of 'Query' sequence: ", length $query_src, "characters\n", "Results for 'Query': \n";

foreach my $key (sort @patterns) {
        print OUT "\t'$key' is seen $query_counts{$key}\n";
        }

print OUT "Total length of 'Sbjct' sequence: ", length $sbjct_src, "characters\n", "Results for 'Sbjct': \n";
foreach my $key (sort @patterns) {
        print OUT "\t'$key' is seen $sbjct_counts{$key}\n";
        }
       
close OUT;


[Copy to clipboard] [ - ]
CODE:
while (my $line = <IN>) {
        chomp $line;
        print "Processing line $.\n";
        }

my $line;
my @words = split /\s+/, $line;

这一段有问题,while里面定义的$line已经Out of scope了
后面的$line只是定义,你又没有赋值,当然是uninitialized value了
真不知道你那while循环是干嘛的


QUOTE:
原帖由 churchmice 于 2008-8-13 20:57 发表

while (my $line = ) {
        chomp $line;
        print "rocessing line $.\n";
        }

my $line;
my @words = split /\s+/, $line;

这一段有问题,while里面定义的$line已经Out of scope ...

程序调 试的时候。后面那个line
3.
出错行。不是指出了是哪一行啊。
点一下。跳过去看看。不就知道了。