#!/usr/bin/perl
#Auteur : Ibouniyamine Nabihoudine
#Date : 16/09/2013
use strict;
use warnings;
use File::Basename;

if ( scalar(@ARGV) < 2 )
{
	print STDERR "Usage : perl $0 <output> <x files>\n";
	exit(1);
}

my $output = shift @ARGV;
my %hash = ();

foreach my $file (@ARGV)
{
    open(TMP, $file) or die"$!";
    while( my $line =<TMP> )
    {
        chomp $line;
        next if ($line =~ /^$/);
        my @F = split(/\t/,$line);
        if ( !exists($hash{$F[0]}) ) 
        {
		    $hash{$F[0]} = [];
    	}
	    push ( @{$hash{$F[0]}}, $F[2]);
    }
    close TMP;
}

open( FINAL , '>', $output) or die "Can't open $output : $!";
foreach my $k (sort ( keys %hash ) )
{
	print FINAL join("\t", $k, @{$hash{$k}}) . "\n";
}
close FINAL;

