########
#	Ahmet R. Ozturk
# 	Emili Lab, University of Toronto, Canada
#	August 28, 2006
#	e-mail: ahmetrasit@gmail.com
########
#	You need to specify the name of the source BIND XML file to be splitted. Resulting file
#	will have a trailer string to indicate the part of the file. In some cases,
#	due to the structure of the source BIND XML file, it might not work properly.


use strict;


my $file = shift @ARGV;

open (RD, $file) or die "Error : $!\n";
while (){
	last if (//);
}

$/ = "\n\n\n";

my $file_count;
my $count;
while(){
	if ($count % 4000 == 0){
		unless ($count == 0){
			print WR '' . "\n";
			print WR '' . "\n";
			print WR '' . "\n";
			print WR '';
			close WR;
		}
		$file_count++;
		open(WR, ">$file.part$file_count") or print "\n\nError : $!\n\n\n";
		
		print WR '' . "\n";
		print WR '' . "\n";
		print WR '' . "\n";
		print WR '' . "\n";
		print WR '' . "\n";

		print "$file.part$file_count is created\n"
	}
	print WR  "$_\n\n\n";
	print "$count\n";
	$count++;
	#last if ($count > 4000);

}

unless($count % 4000 == 1){
	print WR '' . "\n";
	print WR '' . "\n";
	print WR '' . "\n";
	print WR '';
}
print "\n\nTotal exp: $count\nTotal files: $file_count\nIt took ".(time-$^T)." seconds.\n";