Hello I have the following script with I have been pulling my hair out trying to get the second part working. Please keep in mind I am pretty new to Perl. I am having trouble figuring out how to capture the lines which contain the string "RCPT TO" and add each of the captured lines to the correct section below the To: field. One file will contain sometimes contain one or more messages. In this example it contains three messages then what the script does is separates them into three sections, now I want to append all the RCPT lines to it's corresponding sections. This is code I use on a box which saves input from the web. For some reason every time I try to match using the regex for the RCPT line it captures them but then my buffer is empty and only contains the RCPT data. Thanks for the help in advanced.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $lineBufferStatus = 0; my @rcptBuffer = (); my @linesBuffer = (); my $msgUpdateCnt = 0; while (<DATA>) { if ( $_ =~ /^DATA(?:\n|\r\n)$/ ) { print "In second If statement DATA if statement\n"; @linesBuffer = (); $lineBufferStatus = 0; } elsif ( $_ =~ /^\.(?:\n|\r\n)$/ ) { if ( int(@linesBuffer) > 0 ) { while( int(@linesBuffer) > 0 ) { print shift(@linesBuffer); } print "\r\n.\r\nQUIT\r\n"; $msgUpdateCnt++; } $lineBufferStatus = 1; } elsif ( $lineBufferStatus == 0 ) { push( @linesBuffer, $_ ); } } if ( int(@linesBuffer) > 0 ) { my $perMsgRcptBufCnt = 0; while( int(@linesBuffer) > 0 ) { print shift(@linesBuffer); } print "\r\n.\r\nQUIT\r\n"; $msgUpdateCnt++; } if ( $msgUpdateCnt == 1 ) { print "---------------------EQUALS 1--------------------\n"; } elsif ( $msgUpdateCnt > 1 ) { print "---------------------EQUALS 2--------------------\n"; } __DATA__ EHLO testdomain.com MAIL FROM:<outsideuser01@outdomain.com> SIZE=1016 BODY=7BIT RCPT TO:<testuser01@testdomain.com> RCPT TO:<testuser02@testdomain.com> DATA Received: from 1.1.1.1(helo=mvastnlufgt.mgrjofpxydauvu.info) by with esmtpa (Exim 4.69) (envelope-from ) id 1MM6HB-1114fm-3T for testuser01@testdomain.com; Sun, 9 Jan 2011 23:07:59 +0100 From: "outsideuser01" <outsideuser01@outdomain.com> To: <testuser01@testdomain.com> Subject: Re: good evening Date: Sun, 9 Jan 2011 23:07:59 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_ppstll_21_19_24" X-Priority: 3 X-Mailer: choakmps.33 Message-ID: <5C74A867.4001970@aclighting.com> ------=_ppstll_21_19_24 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable H i website: http://canadianph +.tz= hzvebp.ajwcd.ru - CanadianPharmacy ------=_ppstll_21_19_24 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-88 +59-= 1"> <STYLE></STYLE> </HEAD> <BODY> H i <br> website: http://canadianph.tzhzvebp.ajwcd.ru - CanadianPharmacy + = </BODY></HTML> ------=_ppstll_21_19_24-- . RSET MAIL FROM:<Megan@bankofdeerfield.com> SIZE=1016 BODY=7BIT RCPT TO:<testuser36@testdomain.com> RCPT TO:<testuser22@testdomain.com> RCPT TO:<testuser99@testdomain.com> DATA Received: from mdmcfntioehaoqtcmjdmjmcm (192.168.1.33) by wonderware.c +om (80.149.49.194) with Microsoft SMTP Server id 8.0.685.24; Sun, 9 J +an 2011 23:08:07 +0100 Message-ID: <4D2A2627.204070@pacunion.com> Date: Sun, 9 Jan 2011 23:08:07 +0100 From: "Megan" <Megan@bankofdeerfield.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9 +) Gecko/20100921 Thunderbird/3.1.4 MIME-Version: 1.0 To: <testuser36@testdomain.com> Subject: good morning Content-Type: multipart/alternative; boundary="------------02070800106050608090806" X-Priority: 3 X-Mailer: choakmps.33 Message-ID: <5C74A867.4001970@aclighting.com> ------=_ppstll_21_19_24 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi website: http://canadianp= kerur.ru - CanadianPharmacy ------=_ppstll_21_19_24 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-88 +59-= 1"> <STYLE></STYLE> </HEAD> <BODY> H i <br> website: http://canadianp.kerur.ru - GermanPharmacy = </BODY></HTML> ------=_ppstll_21_19_24-- . RSET MAIL FROM:<robertson@roberts.com> SIZE=9916 BODY=7BIT RCPT TO:<testuser2937@testdomain.com> RCPT TO:<testuser22@testdomain.com> DATA Received: from testdomains (172.12.223.44) by wonderware.com (32.34.49 +.194) with Microsoft 23:08:07 +0100 Message-ID: <4D2A2627.204070@pacunion.com> Date: Sat, 8 Jan 2011 17:18:27 +0100 From: "Megan" <robertson@roberts.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9 +) Gecko/20100921 Thunderbird/3.1.4 MIME-Version: 1.0 To: <testuser2937@testdomain.com> Subject: morning Content-Type: multipart/alternative; boundary="------------02070800106050608090806" X-Priority: 3 X-Mailer: choakmps.33 Message-ID: <5C74A867.4001970@aclighting.com> ------=_ppstll_21_19_24 Content-Type: text/plain; . RSET
Using one of the messages as a sample (This is the third message from the __DATA__ section) before and after this is what I am trying to accomplish.
--------THIS IS THE CURRENT OUTPUT-------- Received: from testdomains (172.12.223.44) by wonderware.com (32.34.49 +.194) with Microsoft 23:08:07 +0100 Message-ID: <4D2A2627.204070@pacunion.com> Date: Sat, 8 Jan 2011 17:18:27 +0100 From: "Megan" <robertson@roberts.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9 +) Gecko/20100921 Thunderbird/3.1.4 MIME-Version: 1.0 To: <testuser2937testdomain.com> --------THIS IS THE DESIRED OUTPUT ( I have captured both RCPT TO: lin +es and appended them after the Original To:)-------- Received: from testdomains (172.12.223.44) by wonderware.com (32.34.49 +.194) with Microsoft 23:08:07 +0100 Message-ID: <4D2A2627.204070@pacunion.com> Date: Sat, 8 Jan 2011 17:18:27 +0100 From: "Megan" <robertson@roberts.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9 +) Gecko/20100921 Thunderbird/3.1.4 MIME-Version: 1.0 To: <testuser2937@testdomain.com> To: <testuser2937@testdomain.com> To: <testuser22@testdomain.com>

In reply to Help appending data based on location by perlnewbie9292

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.