#!/usr/bin/perl -- #~ perltidy -csc -otr -opr -ce -nibc -i=4 use strict; use warnings; use autodie; use IO::Handle; Main( @ARGV ); exit( 0 ); sub Main { local *ARGV; local $^I; my $pre = shift @_; local @ARGV = @_; for (@ARGV) { s/^(\s+)/.\/$1/; # leading whitespace preserved s/^/< /; # force open for input $_ .= qq/\0/; # trailing whitespace preserved & pipes forbidden } my $linenum = 0; my $filenum = 0; my $skipped = 0; open FILEOUT, '>', $pre . "-" . $filenum; while () { if (/^\s*$/) { $skipped++; next; } elsif ( $linenum <= 300000 ) { print FILEOUT $_; $linenum++; } elsif ( $linenum > 300000 ) { $linenum = 0; # reset line counter every 300,000 lines $filenum++; # increment file counter every 300,000 lines # and open new file handle close FILEOUT; open FILEOUT, '>', $pre . "-" . $filenum; print FILEOUT $_; } ## end elsif ( $linenum > 300000) } ## end while (<>) close FILEOUT; my $countedLines = ( ( ( $filenum - 1 ) * 300_000 ) + $linenum ); warn "# TOTAL files $filenum \n", ARGV->input_line_number; warn '# ($filenum -1 ) * 300_000 + $linenum = ', "$countedLines\n"; warn "# TOTAL lines ", ARGV->input_line_number, "\n"; warn "# TOTAL SKIPPED $skipped\n"; warn "# COUNTED + SKIPPED = ", $countedLines + $skipped, "\n"; } ## end sub Main