I have a sctipt that check either the last line starts with either TOT or TR . It check that there is date between the first and last line. It also check if the first line start with HD. However, when tried a or statemnet ot check if the first line starts with HD or BAL i always get the output, invlaid header.
#!/usr/bin/perl
$file."DUP.txt";
$bad_header="invalid header";
$bad_trailer="invalid trailer";
$bad_data="no vaild context";
open IN, "$file" || die "Can't open $file $!\n";
if ((-z $file)|| (!-e $file)){
push(@output, $bem_text);
}
my $middle = 0;
while( <IN> ){
if( eof ){
##first is check of data between first and last lines
push(@output, "$bad_data " )unless $middle;
##Check Trailer
push(@output, "$bad_trailer ") unless /^TOT/ || /^TR/;
}
elsif( 2..eof ){
$middle += /\S/;
}
##Check HEADER
push(@output, "$bad_header") if 1..1 and !/^HD/ || !/^BAL/;
}
print "the output is @output";
Start Free Trial