Dan Jones wrote:
The most obvious method is to set $/ to the regex /\n\nFrom /
(messages in mbox format are seperated by a blank line and begin with
a From line) and to read in email messages one at a time.

From "perldoc perlvar": "Remember: the value of $/ is a string, not a regex."

So that method isn't obvious at all; it's not available. (But you can
set $/ to the *string* "\n\nFrom ".)

It seems to me that this would be quite slow.

What made you draw that conclusion?

If you want to preserve the message separators with the right messages,
line by line processing may be the easiest approach:

    my $msgsep = qr(^From );
    my $msg;

    while (<MBOX>) {
        if ( /$msgsep/ ) {
            processmsg( \$msg ) if $msg;
            $msg = $_;
        } else {
            $msg .= $_;
        }
    }
    processmsg( \$msg );

    sub processmsg {
        ...
    }

(The $msgsep regex should probably be more specified.)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to