view rapsodyn/SplitFile4x.pl @ 0:442a7c88b886 draft

Uploaded
author mcharles
date Wed, 10 Sep 2014 09:18:15 -0400
parents
children
line wrap: on
line source

#!/usr/bin/perl
use strict;
use warnings;

my $in = $ARGV[0];
my $NB_LINE_GROUP = $ARGV[1];
my $NB_FILE = 4;
my $out1 = $ARGV[2];
my $out2 = $ARGV[3];
my $out3 = $ARGV[4];
my $out4 = $ARGV[5];

if (!$NB_LINE_GROUP){
	$NB_LINE_GROUP=4;
}

if (!$NB_FILE){
	$NB_FILE=4;
}

my $file_nb = 1;

my @in;
my $current_aggregate;
open(IN, $in) or die ("Can't open $in\n");
while (my $line =<IN>){
	$current_aggregate = $line;
	my $nb_line=1;
	if ($NB_LINE_GROUP>1){
		while (my $add_line = <IN>){
			$current_aggregate .= $add_line;
			$nb_line++;
			if ($nb_line == $NB_LINE_GROUP){
				last;
			}
		}
	}	
	push (@in,$current_aggregate);
}
close (IN);

open (OUT1,">$out1") or die ("Can't open $out1");
open (OUT2,">$out2") or die ("Can't open $out2");
open (OUT3,">$out3") or die ("Can't open $out3");
open (OUT4,">$out4") or die ("Can't open $out4");


for (my $i=0;$i<=$#in;$i++){
	if ($i <= $#in/4){
		print OUT1 $in[$i];
	}
	elsif ($i <= $#in/2){
		print OUT2 $in[$i];
	}
	elsif ($i <= $#in*3/4){
		print OUT3 $in[$i];
	}
	elsif ($i <= $#in){
		print OUT4 $in[$i];
	}
	else {

	}


}  
close (OUT1);
close (OUT2);
close (OUT3);
close (OUT4);