#!/usr/bin/perl
use strict;
use warnings;
# node: 11104399
use constant DIR => ""; #set these as needed...
use constant N_FILES => 3;
# step 1: List all .csv files in a directory by increasing order of file size
my @files_by_size = sort ($a -s <=> $b -s}
;
print join (@files_by_size,"\n"),"\n";
# step 2: Drop the first line of each file and concat the rest into a single output file
open OUT, '>', "BigFile" or die "...blah..$!";
foreach my $infile (@files_by_size)
{
open my $infile, '<', $infile or die "unable to open $infile $!";
<$infile>; #throw away first line of file
print OUT while <$infile>;
}
close OUT; # $infile already closed...
# step 3:Split the above output file into "n" smaller files
# without breaking up the lines in the input files
#
# This is a strange requirement! A VERY strange requirement!
# the obvious thing to do is to make n-1 "big" files and throw
# what is leftover into the nth file (which will be very small)
#
# The tricky part here is to make sure that at least one line
# winds up in the nth file. Now that I think about it...
#
# geez if n==3 and outsize = total bytes,
# Create file1 and write lines >= total_bytes/2 to it.
# write one line to file 2.
# write the rest of lines to file 3.
my $big_files = $n-1;
# stopped at this point because this sounds like a Golf situation
# with a very contrived situation and I'm not good at that.
#step 4: this is easy