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!


The way forward always starts with a minimal test.

In reply to Re: Large FIle Splitter by 1nickt
in thread Large FIle Splitter by insta.gator

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.