Please help me understand errors in perl program

co

#! /usr/bin/perl

use strict;
use warnings;
use diagnostics;

my $amount=""; my $bain; ; my $code="";
my $date;my $day;my $line; my $mo; my $LNUM = 0;
my $xyz=""; my $yr;

$yr = 2015;
my $F; my @F;
while (<>) {
    chop;
    ++$LNUM;
    @F = split(';');
    if ( $F[0] eq "Date" ) { next; }
    elsif ( $xyz eq "" ) { next; }
    else { 
    foreach (@F) {
        $date   = $F[0];
        $code   = $F[1];
    } 
    } elsif ($LNUM==3) {  #ERROR 1
        $line ="EA:\n";
    $line+="bain+\t"+$bain+"\t";
    print $line."\n";
    } elsif ( $yr != 0 ) { #ERROR 2
    printf( "%02d %02d %2s\n", $mo,$day,$code )."\n";
    print $line."\n";
    }  else { #ERROR 3
    print $line."\n";
  }
}

de

---------- Post updated at 05:12 PM ---------- Previous update was at 05:04 PM ----------

perl -c traccTest.pl infile outfile produced:
syntax error at line 34 near "} else if"
syntax error at line 38 near "} else if"
syntax error at line 41 near "}"

I cannot find any obvious pair of braces that seems wrong.
Any help would be appreciated
hpk

Without a sample data file to test this with it's just a hard read.

Try starting a new if block after the else above, which ends the first if block:
} if ($LNUM==3) { #ERROR 1 # change elsif
and
printf( "%02d %02d %2s\n", $mo,$day,$code ); # drop the ."\n"
If you need a newline there add it to the format string "%02d %02d %2s\n\n"