4

运行此代码会产生一个错误,说明“readline() on closed filehandle SEQFILE at line 14”。以前的搜索都评论了如何在 open 之后放置某种类型的条件。这样做只会杀死程序(我把它遗漏了,所以我可以看到它为什么没有打开)。我猜更深层次的问题是为什么它不打开我的文件?

#!/usr/bin/perl -w

#Ask user to point to file location and collect from the keyboard
print "Please specify the file location: \n";
$seq = <STDIN>;

#Remove the newline from the filename
chomp $seq;

#open the file or exit
open (SEQFILE, $seq);

#read the dna sequence from the file and store it into the array variable @seq1
@seq1 = <SEQFILE>;

#Close the file
close SEQFILE;

#Put the sequence into a single string as it is easier to search for the motif
$seq1 = join( '', @seq1);

#Remove whitespace
$seq1 =~s/\s//g;

#Use regex to say "Find 3 nucelotides and match at least 6 times
my $regex = qr/( ([ACGT]{3}) \2{6,} )/x;
$seq1 =~ $regex;
printf "MATCHED %s exactly %d times\n", $2, length($1)/3;
exit;
4

3 回答 3

5

要查看open失败的原因,请更改以下内容:

open (SEQFILE, $seq);

对此:

open (SEQFILE, $seq) or die "Can't open '$seq': $!";

perlopentut参见手册页。)

于 2013-02-22T00:26:16.550 回答
0

另请注意,如果您使用 || 而不是像这样的行中的“或”:

打开 SEQFILE,$seq || die "无法打开 '$seq': $!";

这将无法正常工作。见链接:

https://vinaychilakamarri.wordpress.com/2008/07/27/subtle-things-in-perl-part-2-the-difference-between-or-and/

于 2015-01-22T21:01:57.963 回答
-1

您运行程序的位置与“要打开的文件”的存储位置不匹配。

这是我找到它的地方, Perl Readline on closed filehandle - 文件不存在错误

于 2014-04-23T08:27:18.290 回答