adam_bultman has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, Perl gurus. Here's what I'm working on: I'm reading in a file, and stripping out certain parts of it. What I need to do is be able to include/exclude data by date. There isn't really a "paragraph delimiter" in the file, just tons of text. The only commonality is the line "From mailsnarf <date>", followed by the snarfed email, then another "From...". I want to be able to use from one "From mailsnarf..." to the next one as ONE paragraph, or data glob, and include/exclude data accordingly, only I haven't found quite how to do that yet. Any ideas?

Replies are listed 'Best First'.
Re: Clumping file data together
by Fletch (Bishop) on Oct 18, 2001 at 22:57 UTC

    If you've seen the `on' delimiter, set a flag that you should be printing. Set the flag apropriately whenever a delimiter is encountered. You might also consider Mail::Folder or Mail::Box.

    my $printing; while( <INPUT> ) { if( /^From (\w+)/ ) { if( $1 eq 'mailsnarf' ) { $printing = 1; } else { $printing = undef; } } print if $printing; }
Re: Clumping file data together
by bbfu (Curate) on Oct 18, 2001 at 22:59 UTC

    $/ = "From mailsnarf\n"; while(defined(my $para = <$infile>)) { # ... }

    Update: Or, if it won't always be 'mailsnarf'... (Note: Untested)

    while(defined(my $line = <$infile>)) { next if($line =~ /^From (\w+)$/ ... $line =~ /^From (\w+)$/); # ... }

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.