#!/usr/bin/perl

my @queue;
my $currentNum;
my $totalCount = 0;

if(@ARGV != 3){
	die "Error!\n";
}

push(@queue, $ARGV[0]);

while(@queue){
	$currentNum = shift(@queue);
	open INPUT, "<$ARGV[1]/zygote.$currentNum";
	while(<INPUT>){
		chomp;
		if($_ =~ /clone.+(\d\d\d)$/){
			push(@queue, $1);
		}
	}
	close INPUT;
	system("cp $ARGV[1]/zygote.$currentNum $ARGV[2]");
	$totalCount++;
}
print $totalCount, " files be copied to \"$ARGV[2]\"!\n";
