Error with PERL conditional

0

I am working with a function that allows me to extract text from a mailbox but even though the mailbox is correctly loaded and the text I am looking for through a conditional apparently correct if after the condition I choose to print the result printed it since the condition is not met, the code that appears in the text are 3 numbers plus one space and 3 numbers more separated by points, something that is known as code dsn, example: 550 5.1.1 below the code:

foreach(split(/\n/, $body ) ){
next if(/^\s*$/);

if($_ =~ /^(\d{3}\s\d{1}\.\d{1}\.\d{1})/ig ){
	 $smtpCode = $1;
         print $smtpCode;
}

It should be noted that the uses and variables are initialized.

Edition:

That first validation will repair it but I have many others in which I have to debug the data as much as possible and they are the following:

foreach(split(/\n/, $body ) ){
next if(/^\s*$/);

	if($_ =~ /^(\d{3}\s\d{1}\.\d{1}\.\d{1})/ig ){
		$smtpCode = $1;
	}elsif($_ =~ /^\d{3}\s\d{1}\.\d{1}\.\d{1}\s(.*)$/ig ){
		$smtpCodeDetail = $1;
	}elsif($_ =~ /^Final-Recipient:\sRFC822;\s([A-z0-9_\-\.]+@[A-z0-9_\-\.]+\.\w+)+$/ig ){
	 $email = $1;
	}elsif($_ =~ /^Action:\s(\w+)$/){
	 $smtpAction = $1;
	}elsif($_ =~ /^Status:\s(\d\.\d\.\d)$/){
	 $smtpStatus = $1;
	}elsif($_ =~ /^Diagnostic-Code:\sSMTP;\s(.*)$/){
	 $smtpDiagnosticCode = $1;

	    if(($smtpDiagnosticCode =~ /(550\sSC\-[\d]{3})/ ) or ($smtpDiagnosticCode =~ /(550\sOU\-[\d]{3})/) or ($smtpDiagnosticCode =~ /(550\sDY\-[\d]{3})/) or ($smtpDiagnosticCode =~ /(421\sRP\-[\d]{3})/ ) ){
						$ipTempFiler = 1;
	}
	}elsif($_ =~ /^Remote-MTA:\sDNS;\s([A-Za-z0-9\.\-]+)$/){
		$smtpRemoteMta = $1;
	}elsif($_ =~ /^Last-Attempt-Date:\s[A-Za-z]+\,\s(\d{1,2}\s[A-Za-z]+\s\d{4}\s[0-9:]{8}\s[0-9\-]{5})/ig ){
		$smtpLastAttemptDate = convert_date($1);
	}elsif($_ =~ /^X-RSidusuario:\s(\d+)$/){
		$usuarioId = $1;
	}elsif($_ =~ /^X-RS-idadmin:\s(\d+)$/){
		$adminId = $1;
	}elsif($_ =~ /^X-RS-idcamp:\s(\d+)$/){
		$campanaId = $1;
	}elsif($_ =~ /^X-RS-idlist:\s(\d+)$/){
		$listaId = $1;
	}
    
asked by Luis Alfredo Serrano Díaz 05.12.2018 в 22:03
source

1 answer

2
  • The parentheses of the first if, overrun
  • The "$ _ = ~" part is also left over, but hey, you can leave
  • The "/ ig" indicators are completely over
  • Quantifiers "{1}" overrun
  • In the pattern, the character '^' indicates that the pattern must coincide with the beginning of the line. If it is not at the beginning, it does not find the rest.
answered by 06.12.2018 в 06:35