in reply to print multiple hashes as multiple columns

I think it would make things easier to have a single HoH keyed by your "flag" values with sub-hashes of "contig" and count key/value pairs. This would facilitate accessing everything via keys rather than having to pass separate hashes into a subroutine. It might also look a bit neater if you use printf to make columns line up. Something along these lines perhaps?

knoppix@Microknoppix:~$ perl -Mstrict -Mwarnings -E ' > my %counts = ( > Bact => { A => 3, B => 7, C => 6 }, > Euk => { B => 5, C => 9 }, > Proph_Vir => { A => 8, C => 4, D => 2 }, > ); > my @sortedKeys = do { > my %seen; > sort grep { not $seen{ $_ } ++ } > map { keys %{ $counts{ $_ } } } > keys %counts; > }; > > printf qq{%-10s%4s%4s%4s%4s\n}, q{}, @sortedKeys; > foreach my $flag ( sort keys %counts ) > { > printf qq{%-10s%4s%4s%4s%4s\n}, > $flag, > map { exists $counts{ $flag }->{ $_ } > ? $counts{ $flag }->{ $_ } > : 0 > } @sortedKeys; > }' A B C D Bact 3 7 6 0 Euk 0 5 9 0 Proph_Vir 8 0 4 2 knoppix@Microknoppix:~$

A minor niggle with your code; why chomp comment lines and then discard them? It would make more sense to swap the two lines so you only chomp data lines.

I hope this is helpful.

Cheers,

JohnGG