in reply to Removing Large Invoices from a Data File

Unless you want special handling for the large invoices, it looks like your code is already doing that. Consider the following mutation of your code for demonstration purposes:

use warnings; use strict; my $chunksize = 50; my $filenumber = 0; my $outsize = $chunksize + 1; my $eof = 0; while (<DATA>) { if ($outsize > $chunksize and /^11/) { $outsize = 0; $filenumber++; print "*** New file number $filenumber\n"; } print "$_"; $outsize += length; } __DATA__ 11 The first invoice. We get this whole thing even though it exceeds the 50 character limit because the conditional code requires an invoice marker before it will start a new file. 11 Second 11 Third 11 Fourth invoice 11 Fifth invoice This one is longer, but not excessive 11 Sixth: break before because limit hit in fifth 11 seventh and final

Prints:

*** New file number 1 11 The first invoice. We get this whole thing even though it exceeds the 50 character limit because the conditional code requires an invoice marker before it will start a new file. *** New file number 2 11 Second 11 Third 11 Fourth invoice 11 Fifth invoice This one is longer, but not excessive *** New file number 3 11 Sixth: break before because limit hit in fifth 11 seventh and final

How would the output be different to achieve what you want?


DWIM is Perl's answer to Gödel