gpt4 book ai didi

perl - readline() 在关闭的文件句柄上

转载 作者:行者123 更新时间:2023-12-03 23:17:52 24 4
gpt4 key购买 nike

运行此代码会产生一个错误,指出“第 14 行关闭的文件句柄 SEQFILE 上的 readline()”。以前的搜索都评论过如何在 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;

最佳答案

看看为什么open失败,改变这个:

open (SEQFILE, $seq);

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

(见 the perlopentut manpage。)

关于perl - readline() 在关闭的文件句柄上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15014763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com