in reply to Re^5: Mail::MboxParser pegs the CPU
in thread Mail::MboxParser pegs the CPU

> Have you tried?

I have. I explicitly said so in the post to which you just replied.

I can get a printout similar to the above, but as I understand it, it's just a demonstrator tool that lets you "peek at the index" - that's what the docs say. I'm not clear on how that's supposed to help, or speed up the retrieval - which is what I'm trying to do.

If you know how I can use this to speed up the retrieval, please enlighten me.

P.S. I have both Mail::Mbox::MessageParser::Cache and Mail::Mbox::MessageParser::Grep installed - they were installed even before I posted my question here.


--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^7: Mail::MboxParser pegs the CPU
by zwon (Abbot) on Jan 16, 2010 at 16:15 UTC
    If you know how I can use this to speed up the retrieval

    First you have to build index and save it into a file:

    use strict; use warnings; use Mail::MboxParser; use Storable; my $mbox = shift; # name of the mailbox file my $mb = Mail::MboxParser->new( $mbox ); $mb->make_index; my @index; # Build index. I'm adding message position and subject # into index, but you can add also other fields. for ( 0 .. $mb->nmsgs - 1 ) { push @index, [ $_, $mb->get_pos($_), $mb->get_message($_)->header- +>{subject} ]; } # save index into file store \@index, "$mbox.idx";

    Then you can retrieve index from the file, get position of message you want, and directly read that message. The following example takes mbox file name as first argument and message number as second.

    use strict; use warnings; use Mail::MboxParser; use Storable; my $mbox = shift; my $num = shift; # loading index my $index = retrieve("$mbox.idx"); unless (defined $num) { # print index print join(" => ", @$_), "\n" for @$index; } else { # print message $num die "No such message" if $num >= @$index; my $mb = Mail::MboxParser->new( $mbox ); $mb->set_pos($index->[$num][1]); print $mb->next_message_old; }