mroberts 0 Newbie Poster

I am somewhat new to Perl and I am getting the wrong result.
The parser part works great and it sorts out like I want. However as it reads through and parses the file I can get it printed out to an out file however I can not seem to check for the presence of 'AAA' within the string to send a different message. Any help is appreciated. I am guess ing I am reading the variables wrong

 use X12::Parser;
open (myoutfile, ">filetest.out"); 
# Create a parser object
my $p = new X12::Parser;


# Parse a file with the transaction specific configuration file
$p->parsefile ( 
    file => 'C:\navicure\mednextengine\inbound_edi\test4.271',
    conf => 'C:\x12parser1\x12\cf\271_004010X092.cf' 
);
 # Step through the file 
while ( my $loop = $p->get_next_loop  ) {
    my @loop = $p->get_loop_segments;$aaaelement=@loop;print $aaaelement;if ($aaaelement =~ /AAA/) {print  "Invalid Request";print myoutfile "  \n";};  
$firstelement = shift(@loop); $firstelement =~ s/\*/ /g;
$secondelement = shift(@loop); $secondelement =~ s/\*/ /g;
if ((@loop) =~ /AAA/)       {print myoutfile "Invalid Request";print myoutfile "  \n";}; 
if ($firstelement =~ /^EB/)     {print myoutfile $firstelement;print myoutfile "  \n";};
if ($secondelement =~ /MSG/)    {print myoutfile $secondelement;print myoutfile "\n";};

}

close (myoutfile);