I'm not so sure Flech is right about the file not starting with a "From " line, I think it's just not starting with a "From ... 2003" line. The way I read what you're doing, you're using something like
while (<FILE>) { if (/^From .+ 2003/) { $mails[$#mails + 1] = $_; } else { $mails[$#mails] .= $_; } print $OUT, @mails; }
The else tries to add lines to an array bin that the "From " test has not created, because it hasn't yet gotten to the section of the emails from 2003 that you want. Try something like
while (<FILE>) { if (/^From /) { if (/2003/ || $mailsStarted) { $mails[$#mails + 1] = $_; $mailsStarted = 1; } } elsif ( $mailsStarted ) { $mails[$#mails] .= $_; } print $OUT, @mails; }

Note that you will get some non-2003 emails that come after the first 2003 email, but that should be ok.


In reply to Re: Spliting an mbox file by rodion
in thread Spliting an mbox file by monger

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.