Processing order seems to be the problem as Albannach points out. I haven't read his post closely, but here is a modified version of your program that seems to run correctly with a data set that I copied/modified from a sendmail inbox:
use strict; my $flag = '0'; ### I had to take a few of the extra blanks out of the next three se +arch variables my $from = 'From: '; my $full_subject = 'Subject: '; my $date = 'Date: '; my @buffer = (); my @spamcop_email_array = <DATA>; open (TEXTOUT, ">junk.out") || die "Can't open 'junk.out'"; #loop and fill @buffer# foreach (@spamcop_email_array){ if(s/.*$from//){ ### changed [0] to [1] $buffer[1] = $_; $flag = 0; } if(s/.*$full_subject//){ ### changed [1] to [2] $buffer[2] = $_; $flag = 0; ### moved print from date if block to here print TEXTOUT @buffer; } if(s/.*$date//){ ### changed [2] to [0] $buffer[0] = $_; $flag = 0; } } close TEXTOUT; __DATA__ From MAILER-DAEMON Fri Jan 4 18:04:20 2002 Date: 04 Jan 2002 18:04:20 -0600 From: Mail System Internal Data <MAILER-DAEMON@loopey.faraway.net> Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA Message-ID: <1010189060@loopey.faraway.net> X-IMAP: 0910805650 0000003175 Status: RO This text is part of the internal format of your mail folder, and is n +ot a real message. It is created automatically by the mail system softwa +re. If deleted, important folder data will be lost, and it will be re-crea +ted with the data reset to initial values. From root@loopey.faraway.net Sun Jun 20 10:37:57 1999 Received: from localhost (root@localhost) by loopey.faraway.net (8.8.8+Sun/8.8.8) with ESMTP id KAA05403 +; Sun, 20 Jun 1999 10:37:57 -0500 (CDT) Date: Sun, 20 Jun 1999 10:37:56 -0500 (CDT) From: Super-User <root@loopey.faraway.net> To: <light@loopey.faraway.net>, xxxx xxxxx <joey@loopey.faraway.net> Subject: Re: accounts for DISL (fwd) Message-ID: <Pine.GSO.4.10.9906201036380.5380-100000@loopey.faraway.ne +t> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Length: 1064 Status: RO X-Status: X-Keywords: X-UID: 263 joey, Looks like you may have sent Randy a note from root - here's her rep +ly. I'll address the SAS issues. - Andy ---------- Forwarded message ---------- Date: Fri, 18 Jun 1999 09:01:04 -0500 From: rsch <rsch@xxxx.xxx> To: Super-User <root@loopey.faraway.net> Subject: Re: accounts for DISL joey, If possible I would like to keep my account (rsch) to run SAS jobs for the faculty from time to time. Thanks, Randy From light@loopey.faraway.net Wed Mar 28 12:05:57 2001 Date: Wed, 28 Mar 2001 12:05:48 -0600 (Central Standard Time) From: xxxx xxxx <light@loopey.faraway.net> To: xxx xxx xxx <joey@loopey.faraway.net> Subject: xxxxx account Sender: light@loopey.faraway.net MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Length: 364 Status: RO X-Status: X-Keywords: X-UID: 1565 joey, when you get a chance, could you please do whatever is necessary to remove xxxx xxxxx xxxxx account? We will want to leave a forwarding record in place in the aliases file.
The output file:
04 Jan 2002 18:04:20 -0600 Mail System Internal Data <MAILER-DAEMON@loopey.faraway.net> DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA Sun, 20 Jun 1999 10:37:56 -0500 (CDT) Super-User <root@loopey.faraway.net> Re: accounts for DISL (fwd) Fri, 18 Jun 1999 09:01:04 -0500 rsch <rsch@xxxx.xxx> Re: accounts for DISL Wed, 28 Mar 2001 12:05:48 -0600 (Central Standard Time) xxxx xxxx <light@loopey.faraway.net> xxxxx account
While this code works in most cases, you should really beef it up with some error checking. I seem to remember a recent post that described a CPAN module that parses email. If so, you might consider switching since it might be vetted already and insure more accurate results. BTW, I guess that $flag will serve a future purpose. It doesn't seem to do anything now.

HTH,

--Jim


In reply to Re: The contents of a misguided array. by jlongino
in thread The contents of a misguided array. by amearse

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.