Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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


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 wandering the Monastery: (11)
As of 2015-07-03 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls