Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: Subsetting text files containing e-mails

by GrandFather (Cardinal)
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


Comment on Re^5: Subsetting text files containing e-mails
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-09-16 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls