in reply to Re: spliting large file into smaller
in thread spliting large file into smaller

Here's a simpler version:

open(my $fh_in, '<', "filein.dat") or die("Unable to open filein.dat: $!\n"); my $fh_out; my $file_count = 0; while (<$fh_in>) { if ($. % 30 == 1) { open($fh_out, '>', "file${file_count}.dat") or die("Unable to create file${file_count}.dat: $!\n"); ++$file_count; } print $fh_out ($_); }

The redundancy was eliminated. The buffer was eliminated.

You might need a close before the open.