我有一個腳本,在其中詢問用戶是否要輸入文件。如果他這樣做&該文件不是空的比我想要使用此文件並打開輸出文件的結果。我想重複這個問題3次,以便用戶可以導入最多3個文件。這是我的腳本看起來像:只有在輸入文件不爲空的情況下才打開輸出文件
(12) my $genes1;
(13) my $genes2;
(14) my $genes3;
(16) if (prompt_yn("Do you want to import a genelist for filtering?")){
(17) my $genelist1 = prompt("Give the name of the first genelist file:\n");
(18) print "genelist1 = \"$genelist1\"\n";
(19) open($genes1,'<',$genelist1) or die "Could not open file $genelist1 $!";
(20) if (prompt_yn("Do you want to import another gene list file?")){
(21) my $genelist2 = prompt("Give the name of the second genelist file:\n");
(22) print "genelist2 = \"$genelist2\"\n";
(23) open($genes2,'<',$genelist2) or die "Could not open file $genelist2 $!";
(24) if (prompt_yn("Do you want to import another gene list file?")){
(25) my $genelist3 = prompt("Give the name of the third genelist file:\n");
(26) print "genelist3 = \"$genelist3\"\n";
(27) open($genes3,'<',$genelist3) or die "Could not open file $genelist3 $!";
(28) }
(29) }
(30) }
(32) print "genes1 = \"$genes1\"\n";
(33) print "genes2 = \"$genes2\"\n";
(34) print "genes3 = \"$genes3\"\n";
(45) my $genelist1filter;
(46) my $genelist1restfilter;
(47) my $genelist2filter;
(48) my $genelist2restfilter;
(49) my $genelist3filter;
(50) my $genelist3restfilter;
(51) printf "At line %d\n", __LINE__;
(52) print "genes1 is ", defined $genes1 ? "defined\n" : "not defined\n";
(53) print "genes2 is ", defined $genes2 ? "defined\n" : "not defined\n";
(54) print "genes3 is ", defined $genes3 ? "defined\n" : "not defined\n";
(56) if (-e $genes1 && -s $genes1){
(57) printf "At line %d\n", __LINE__;
(58) open($genelist1filter, '+>', "genelist1_missense_nonsense_frameshift_inframe_startloss_stoploss.txt") || die "Can't write new file: $!"; printf "At line %d\n", __LINE__;
(59) #first output file
(60) open($genelist1restfilter, '+>', "notingenelist_missense_nonsense_frameshift_inframe_startloss_stoploss.txt") || die "Can't write new file: $!"; #second output file
(61) } # same for $genes2 and $genes3
(62) printf "At line %d\n", __LINE__;
# line56 to 62 is repeated for $genes2(lines63-69) and for $genes3(lines70-77)
(183)# genelist2 filtering
my %hash2=();
while(<$genes2>){
chomp;
#next unless -z $_;
my $keyfield = $_;
$hash2{$keyfield}++;
(190) }
(201)# genelist3 filtering
my %hash3=();
while(<$genes3>){
chomp;
#next unless -z $_;
my $keyfield = $_;
$hash3{$keyfield}++;
(208) }
現在,當我測試這個腳本,並讓用戶輸入1 genelist(所以「是」第一個問題&提供姓名)&然後回答「不」的第二個問題),我得到的消息是在-e附近使用了一個單位化的值,在$genes2
和$genes3
附近。我想-e
和-s
有什麼問題來檢查文件是否存在並且不是空的?有人可以對此發表評論嗎?
這是輸出的樣子(基於編輯從AndrianHHH腳本)
Do you want to import a genelist for filtering? (Y/N): y
Give the name of the first genelist file:
genelist1.txt
genelist1 = "genelist1.txt"
Do you want to import another gene list file? (Y/N): n
genes1 = "GLOB(0x134c568)"
Use of uninitialized value $genes2 in concatenation (.) or string at filtering.pl line 33, <STDIN> line 3.
genes2 = ""
Use of uninitialized value $genes3 in concatenation (.) or string at filtering.pl line 34, <STDIN> line 3.
genes3 = ""
At line 51
genes1 is defined
genes2 is not defined
genes3 is not defined
At line 57
At line 58
At line 62
Use of uninitialized value $genes2 in -e at filtering.pl line 63, <STDIN> at line 3 At line 69
Use of uninitialized value $genes3 in -e at filtering.pl line 70, <STDIN> line 3.
At line 77
Use of uninitialized value $genes2 in <HANDLE> at filtering.pl line 185.
readline() on unopened filehandle at filtering.pl line 185.
Use of uninitialized value $genes3 in <HANDLE> at filtering.pl line 203.
readline() on unopened filehandle at filtering.pl line 203.
在添加語句時更改此 – user1987607
時仍會收到相同的消息,它將顯示:「定義基因1」。之後,我得到了和以前一樣的信息 – user1987607
我使用的是perl 5版本14 subversion 2.這確實是我的代碼。我可以給你發送輸出嗎? – user1987607