Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^5: Subsetting text files containing e-mails

by GrandFather (Sage)
on Jan 27, 2012 at 09:17 UTC ( #950295=note: print w/replies, xml ) Need Help??

in reply to Re^4: Subsetting text files containing e-mails
in thread Subsetting text files containing e-mails

You don't need more than one pass through the source file. Just create the output files as you need them. In sketch you'd have something like:

use strict; use warnings; my $emailNum; my $outFile; $/ = ''; # Set readline to "Paragraph mode" while (<DATA>) { if (!$emailNum || /^From:/im) { close $outFile if $outFile; my $fname = sprintf "mails_%06d.txt", ++$emailNum; open $outFile, '>', $fname or die "Can't create $fname: $!\n"; } print $outFile $_; }
True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950295]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2016-10-25 01:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.