On Mon, Aug 25, 2003 at 05:19:14PM -0700 nntp.perl.org wrote:

> I have had success now using Mail::MboxParser for all my basic mail parsing
> needs, like getting subject, from, to.  Now bossman wants me to do more
> extensive regex filtering and grabbing weird data in the email body.
> 
> I wrote a little test script, shown below.  I am able to get the
> "appointment date" data, contained in the message body, that I am looking
> for, but only for the first record.  The while loop keeps looping back to
> that record.  Also, I cannot get to the next line that has the "comments
> section" for each email.  I know this has got to be something stupid I am
> not seeing, but after looking at this for so long, everything is starting to
> blur together.  Would anyone have any insight as to my mistake?

You want to loop over the lines of the body, right?

> #!/usr/bin/perl
> use Mail::MboxParser;
> my $mb=Mail::MboxParser->new('MyMailbox', decode => 'ALL');
> 
> #grab data from the body of the message
>   while (my $msg = $mb->next_message) {
>   $test = $msg->body($msg->find_body) ;
>      while (defined($_=$test)) {

That's an infinite loop. If you want to iterate over the lines of a
body, try

        for ($test->as_lines) {
            # each line now in $_
            if (/App:.*Date:\s+(.{0,8})\s+Time:/) {
                ...
            } 
            else if (/Comments/) {
                ...
            }
            
>           if ($test =~ /App:.*Date:\s+(.{0,8})\s+Time:/) {
>                  #looking for appointment data here
>                  print "I see the appointment date is $1", "\n";
>           } elsif ($test =~ /Comments/) {
>                  while (($test=<>) !~ /(Notification|XEDB)/) {

What should this while-loop achieve? <> reads from STDIN. I am sure you
don't want that.

>                      $comments .= $_;
>                      chop($comments);
>                      $comments .= " ";
>                      print "The comments are", $comments;
>                  }#end while ($test=<>)
>           }#end elsif
>       }#end while (defined($_=$test)) {
>   }#while (my $msg = $mb->next_message)

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to