use Modern::Perl; use File::Slurp qw/read_file/; use Text::Table; use Data::Dumper; my ( %supermatrix, @titles, %seen, @rows ); my @list = read_file 'LIST.txt'; for ( my $i = 0 ; $i < $#list + 1 ; $i += 2 ) { my ($substrateID) = $list[$i] =~ /(\d+)/g; $supermatrix{$substrateID}{$1} = 1 while $list[ $i + 1 ] =~ /(\d+)/g; } for my $product ( read_file 'SUPERLIST_PRODUCT.txt' ) { my ($productID) = $product =~ /(\d+)/g; push @titles, $productID unless $seen{$productID}++; for my $substrate ( read_file 'SUPERLIST_SUBSTRATE.txt' ) { my ($substrateID) = $substrate =~ /(\d+)/g; $supermatrix{$substrateID}{$productID} //= '.'; } } my $titles = join ',', map "{title => 'p$_', align_title => 'center', align => 'center'}", sort { $a <=> $b } @titles; for my $y ( sort { $a <=> $b } keys %supermatrix ) { #rows my ( $rowLable, @row ); for my $x ( sort { $a <=> $b } keys %{ $supermatrix{$y} } ) { #columns $rowLable = $y unless $rowLable; push @row, $supermatrix{$y}{$x}; } push @rows, [ "s$rowLable", @row ]; } my $tb = Text::Table->new( ' ', eval $titles ); $tb->load(@rows); say $tb; say "\n", Dumper \%supermatrix;