I've accumulated an mbox file from a maillist that's grown to about one half of a gig. Needless to say, I'm having trouble getting Thunderbird, or any other mbox mail client, to read the file and, if necessary, create an index to it. So, my plan is to split it up into more manageable parts. First try: year. Here's what I'm thinking: First, I did some diging around the Monestary, in dusty corners and stumbled upon this thread that gave me the start. My code is based off of this snippet. Here's my modded code:
#!/usr/bin/perl -w my $file = "./oldcoffee.tmp"; my $out = ">./coffee.tmp"; my @mails; open OUT, $out || die "Can't open $out!\n"; open FILE, $file || die "Can't open file oldcoffee!\n"; while (<FILE>) { if (/^From /) { $mails[$#mails + 1] = $_; } else { $mails[$#mails] .= $_; } print $OUT, @mails; } close FILE, $file || die "Can't close file oldcoffee!\n"; close OUT, $out || die "Can't close $out!\n";
What I want to do is modify the pattern matching in the if clause to add the year. Here's an example ^From line:

From - Tue Jan 14 17:43:12 2003

I've looked at constructing a regex to account for the day, date and time, then iterate through for each year, 2003-2006. The regex got to be a bit cumbersome, so I tried this:

if (/^From - \+ 2003/)
With this, I receive the following error:

Modification of non-creatable array value attempted, subscript -1 at ./mbox_orig.pl line 13, <FILE> line 1.

Any suggestions on how to tackle this? Thanks, monger

monger |------------------------| munging perl on the side

In reply to 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.