in reply to Re: Memory Problems with Parsing
in thread Memory Problems with Parsing

The way the document looks, it starts with "From..." or at least that's how each day in the log starts. As it worked well with grabbing the date, with $_=~"Sent:", I figured it would work fine to tell if at this point (per domain breakdown) grab everything and put it into a list, until reaching from, in which case it would need to start all over. Maybe I'm misunderstanding the until statement though. Thanks for the regular expression tip, will put to good use!

Replies are listed 'Best First'.
Re^3: Memory Problems with Parsing
by TGI (Parson) on Jul 30, 2007 at 16:55 UTC

    I think the problem is that you are misunderstanding how your program moves through your file. $_ only changes when the outer while loop completes.

    Consider this code:

    while ( <DATA> ) { chomp; until( /[^\d]/ ) { print "$_"; } } __DATA__ 1 A B C

    This code will never terminate, it will just print '1' forever. The outer while block never completes and it never sees past the first line returned by the special DATA filehandle.

    Try setting a flag to indicate what you should be looking for in your while loop. Use either an if-else chain or a dispatch table to handle each case.


    TGI says moo

      I recently fixed this, I actually doubted perl taking in all of those lines. The code now looks like this
      while(<>){ if (/^[0-9]+, |Sent:/){ push (@logs, $_); }# elsif (/Sent:/) { # push (@dates, $_); #} } print $logs[0]; print $logs[1]; #print @dates;
      The Comments are there because I tried making it one statement, so as it goes through the file it now keeps the logs and dates together. The until statement was my problem, I guess learning from mistakes is always the best. Thanks for the help!