in reply to Large FIle Splitter
Hi insta.gator,
Your code has lots of unneccessary cruft that makes it hard to read, a lot having to do with quotation ... I suggest a closer read through some introductory material such as perlsyn (Perl Syntax).
I cleaned up your code down to your problem line. It's below for your review. Untested and incomplete but should give you some ideas. Some things I did include:
In doing so I can see at least one issue which is that you are opening your OUTFILE1 each time through your while loop. I still can't see exactly what your problem is, but it looks like you want to stop writing to the file if it's reached a certain size, but not split a line. You think you're going to split a line, so you want to back up and start the next file from the start of the broken line. Right? Anyway, it's a lot like an XY Problem, and there are lots of ready-made solutions (check CPAN) that will allow you skip writing all that code yourself.
foreach my $filename (@prfiles) { my ( $total_recs, $counter_recs, $previous_rec_ssn, $file_count, $ +file_size_met ); open ( my $INFILE1, '<', $filename ) or die "Cannot open $filename +: $!"; print "Now processing: $filename\n"; while ( <$INFILE1> ) { if ( not $file_size_met ) { ++$file_count; my $mod_filename = $filename . $file_count; print "Writing output to: $mod_filename\n\n"; open ( my $OUTFILE1, '>>' $mod_filename ) or die( 201 ); while ( $counter_recs < 50000 ) { print $OUTFILE1 $_; ++$total_recs; ++$counter_recs; } print "$total_recs records have been processed\n"; $counter_recs=0; } my $actual_size = (stat($mod_filename))[7]; ++$file_size_met if $actual_size >= $outsize; print "Current file size is $actual_size bytes.\n";
Hope this helps!
|
|---|