Perl打开时出现语法错误

时间:2015-06-08 23:34:02

标签: perl syntax-error conditional-statements

我将以下条件代码作为我脚本的一部分,并且仅在最后一次open调用时遇到语法错误。建议?

if ($contig_string =~ /($pattern)/) {
        print "$ERR_number \n";
        print "Found forward pattern.\n";
        print "Pattern found is: $1 \n";
        $position = index($contig_string,$1);
        print "Index returned: $position \n";
        $substr_forward = substr($contig_string, $position, -2000);
        print "$substr_forward \n";  
        open (REPORT, ">>", spacer_contigs) or die "Could not open";
        print REPORT ">$ERR_number \n";
        print REPORT "$substr_forward \n";
        }
elsif ($contig_string =~ /($pattern_reverse)/) {
        print "$ERR_number \n";
        print "Found reverse pattern.\n";
        print "Pattern found is: $1 \n";
        $position_reverse = index($contig_string,$1);
        print "Index returned: $position_reverse \n";
        $substr_reverse = substr($contig_string, $position_reverse, 2000);
        print "$substr_reverse \n";
        open (REPORT, ">>", spacer_contigs) or die "Could not open";
        print REPORT ">$ERR_number \n" or die "Could not append";
        print REPORT "$substr_reverse \n";

        }
elsif ($contig_string !~ /$pattern_forward/) {
        print "$ERR_number \n";
        print "Did not find pattern. \n"
        open (NOMATCH, ">>", no_match) or die "Could not open"; # SYNTAX ERROR
        print NOMATCH ">$ERR_number \n" or die "Could not append";      

        }

1 个答案:

答案 0 :(得分:7)

您在导致问题的print之前的open上错过了分号。

此外,很少需要在换行前输出空格。你有很多字符串,如:

print "Did not find pattern. \n"   # This is where the semicolon should be

最好写成:

print "Did not find pattern.\n";