Perl打开时出现语法错误

0 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";      

        }
Run Code Online (Sandbox Code Playgroud)

Jon*_*ler 7

在你造成麻烦print之前,你错过了一个分号open.

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

print "Did not find pattern. \n"   # This is where the semicolon should be
Run Code Online (Sandbox Code Playgroud)

那会写得更好:

print "Did not find pattern.\n";
Run Code Online (Sandbox Code Playgroud)