Syntax error in Perl open

536 views Asked by At

I have the following conditional code as part of my script and I keep getting a syntax error for only the last open call. Suggestions?

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

There are 1 answers

0
Jonathan Leffler On

You're missing a semicolon on the print before the open that is causing trouble.

Also, there's seldom a need to output blanks before newlines. You have numerous strings such as:

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

that would be better written as:

print "Did not find pattern.\n";