我有一个脚本,我在其中询问用户是否要输入文件。如果他这样做并且文件不是空的,那么我想使用这个文件并打开一个输出文件以获得结果。我想重复这个问题 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 个基因列表(所以对第一个问题“是”并提供一个名称)然后对第二个问题回答“否”),我收到消息,即在-e 附近$genes2
和$genes3
。我想-e
and-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.