You could open the directory with opendir and read it with readdir. Iterate over the names returned by readdir. Use the -f operator to make sure you've got a file. Using the -s operator, you could determine the file size. Set $/ to \1048576. Open the too-big file. Start up a while loop, reading through the file. For each "record", open an output file and print out that record, then close that output file, and move onto the next file in the directory. Use a counter to generate unique splitfile names.
Update:
A few hours later I had a moment to put it to code:
use strict;
use warnings;
my $path = "c:/path/to/files";
my $maxsize = 1048576;
opendir my $dirhandle, $path or die $!;
foreach my $file ( readdir $dirhandle ) {
next unless -f $file;
next unless -s $file > $maxsize;
my $count = 0;
open my $in, '<', "$path/$file" or die $!;
{
local $/ = \$maxsize;
while ( my $record = <$in> ) {
my $outname = "$file.split"
. sprintf "%03s", $count++;
open my $out, '>', "$path/$outname" or die $!;
print $out $record;
close $out or die $!;
}
}
close $in;
}
|