Note that this version includes the stop string in the previous file. If you want it included in the next file:use strict; use warnings; my ($fsize, $csize, $file, $fcount, $read, $in, $out, $chunk); $fsize = 1024 * 1024 * 200; # Size of file you want $csize = 1024 * 1024; # Size of chunks $/ = "\n"; # String to stop at $file = "test.dat"; $fcount = 1; # Number for file names $read = 0; $out = nextfile($file, $fcount); open($in, $file); while (read($in, $chunk, $csize) == $csize) { print $out $chunk; $read += $csize; if ($read >= $fsize) { print $out $_ = <$in>; $read = 0; close($out); $out = nextfile($file, $fcount); } } close($in); close($out); sub nextfile { my ($name, $handle) = $_[0]; $name =~ s/\./$_[1]./; $_[1]++; open($handle, ">$name"); return $handle; }
if ($read >= $fsize) { chomp($_ = <$in>); print $out $_; $read = 0; close($out); $out = nextfile($file, $fcount); print $out $/; }
In reply to Re: File Processing...
by TedPride
in thread File Processing...
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |