運行此代碼會生成一個錯誤,指出在第14行關閉的文件句柄SEQFILE上的「readline()」。之前的搜索都評論了在打開後應如何放置某種條件。這樣做只會殺死程序(我離開它,所以我可以看到它爲什麼沒有打開)。我猜想更深層次的問題是爲什麼它不打開我的文件?關閉的文件句柄上的readline()
#!/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是更好:) – squiguy 2013-02-22 00:27:30
它說:「沒有這樣的文件第11行,行 1」,但我知道這個文件是存在的! –
Citizin
2013-02-22 00:34:48
@Citizin:打印的$ seq'的值是多少? – ruakh 2013-02-22 00:35:39