#!/usr/bin/perl

my @files;
my $label;
my $order;
my $counter = 0;
my $julian;


@files = glob("./*.110");

open(FILEIN, "$files[0]") || die ("blubb");


$julian = <FILEIN>;

$julian = length(($julian)) - 1;

foreach $file (@files) {
	$counter++;
	open(FILEIN, "<$file") || die ("kann net offnen $file .");

	$label .= "[".$counter."] ".substr(<FILEIN>, 4);
	$order .= <FILEIN>;
}

my $nexheader= << "NEX";
#NEXUS
BEGIN taxa;
	DIMENSIONS ntax=$counter;
TAXLABELS
$label;
END;
BEGIN characters;
	DIMENSIONS nchar = $julian;
	FORMAT
		labels = no
		symbols = "0 1"
	;
	MATRIX
$order;
END;
NEX

print $nexheader;


exit;
