Perl open中的语法错误

Perl open中的语法错误,perl,syntax-error,conditional-statements,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); pr

我的脚本中包含以下条件代码,并且只在最后一次
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";      

        }

您在
打开
之前的
打印
上缺少分号,这会造成问题

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

print "Did not find pattern. \n"   # This is where the semicolon should be
这最好写为:

print "Did not find pattern.\n";

需要澄清的是,
**
是否表示强调/粗体?标记样式在代码块中不可用。最好在靠近行的代码段中添加注释,或者将代码段缩短到真正需要的长度。此外,如果您可以在帖子中包含错误给出的消息,这通常会有所帮助。您在前一行中缺少分号,您的
die
消息也会混淆<代码>>是追加,而
是覆盖。当您检查
打开的
调用的状态时,您应该始终包括内置变量
$的值die
字符串中输入code>,说明打开的原因failed@UMD2UCSF字体请看一看