4

このコードを実行すると、「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;
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 に答える