in reply to spliting large file into smaller
open(my $in, '<', "filein.dat") or die("Unable to open filein.dat: $!\n"); my @buf; my $file_count = 0; while (<$in>) { push(@buf, $_); if (@buf == 30) { open(my $fh_out, '>', "file${file_count}.dat") or die("Unable to create file${file_count}.dat: $!\n"); print $fh_out ($_) foreach @buf; @buf = (); ++$file_count; } } if (@buf) { open(my $fh_out, '>', "file${file_count}.dat") or die("Unable to create file${file_count}.dat: $!\n"); print $fh_out ($_) foreach @buf; }
Update: Changed
print($fh_out)
to
print $fh_out ($_)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: spliting large file into smaller
by ikegami (Patriarch) on Nov 10, 2005 at 23:41 UTC |