Hello all,

I have 4 hashes for counting certain hits for many contigs and I would like to print the combined output as a table. For ex. $Hit1{$contigA}=4, $Hit2{$contigA}=5, $Hit4{$contigA}=1 I would like the following output:

contigA 4 5 0 1 contigB 10 1 1 0 etc.

looking for inspiration/help I found this subroutine zup. However, I am slightly confused by zup, and can't see how to extend it too hashes, also I would have to put in some check and if a count doesnt exist for that contig/Hit combo then make it zero.

any help is appreciated

##zup
#!/usr/bin/perl use strict; use warnings; no warnings qw /syntax/; sub zup { join "\n" => map {join " " => map {shift @$_} @_} @{$_ [0]} } my @array1 = qw /ab bc cd de/; my @array2 = qw /cc dd ee gg/; my @array3 = qw /12 34 56 78/; print zup \(@array1, @array2, @array3); print "\n";
##my script so far
use strict; use warnings; my $infile=$ARGV[0]; open (IN,$infile) or die "cannot open $infile"; my %count_Bact; my %count_undef; my %count_ProphVir; my %count_Euk; while (my $line=<IN>) { chomp $line; next if ($line =~/^#/) ; my ($geneid,$cons_flag)=split(/\t/,$line); my @geneid_columns=split(/_/,$geneid); my $contig=join("_",$geneid_columns[0],$geneid_columns[1],$gen +eid_columns[2],$geneid_columns[3]); if ($cons_flag eq "Bact"){ $count_Bact{$contig} ++; } if ($cons_flag eq "undef"){ $count_undef{$contig} ++; } if ($cons_flag eq "Proph_Vir" || $cons_flag eq "Vir" || $cons_ +flag eq "Proph"){ $count_ProphVir{$contig} ++; } if ($cons_flag eq "Euk"){ $count_Euk{$Euk} ++ ; } } close (IN);

In reply to print multiple hashes as multiple columns by AWallBuilder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.