> set size arguments
> set input file
> set output file
>
> open the file
> read the content
> print line of the content to $output file
> check size of $output file
> continue if not to big yet
> else
> check which files already live in the target directory (.1 .2 .3 .4 .5 etc)
> rotate file to $output file.1 (or .2 .3)
> and restart the printing process
Here is the splitting portion:
#! /usr/local/bin/perl
use strict;
use warnings;
# Example data - 85_782 lines, 1_072_787 (words), 10_313_190 bytes - filename: syslog
my $split_into = 3;
my $line_cnt;
my $counter;
my $x;
open (ROFILE, "syslog") or die "cannot open syslog $!";
while(<ROFILE>) { ++$line_cnt; }
close (ROFILE) or die "cannot close syslog $!";
open (ROFILE, "syslog") or die "cannot re-read syslog $!";
for ($x=0; $x < $split_into; ++$x) {
open (WOFILE, ">syslog.$x") or die "cannot write to syslog.$x $!";
while(<ROFILE>) {
print WOFILE $_;
++$counter;
last if ($counter >= ($line_cnt/$split_into));
}
$counter = 0;
close (WOFILE) or die "cannot close syslog.$x $!";
}
close (ROFILE) or die "cannot close syslog $!";
print "Done ... \n\n";
__END__
Cheers!
-Sx-
--
Overheard: Isn't this all kinda sudden? Mentor: Yes. Sometimes,
you just know that it's time to say goodbye. And the moment you know
it, you must do it. Teaching students on anything less than 100%
motivation and energy is not how it should be done.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>