Open the file only when $postfix changes. In addition, you can get a little easier.
use warnings; use strict; use autodie qw(:all); my $tot = 0; my $postfix = 'A'; my $threshold = 100; open my $fop, '>>', 'output_' . $postfix; open my $fip, '<', 'input.txt'; while (my $line = <$fip>) { $tot += substr( $line, 10, 5 ); if ($tot >= $threshold) { $tot = 0; $postfix++; close $fop; open $fop, '>>', 'output_' . $postfix; } print {$fop} $line; } close $fip; close $fop;
dan1111
source share