Could you please take a look at this and let me know if there's any logical error? I think it works well.. Also if you can give me any suggestions, please do not hesitate to reply / message. Thank you so much!! (***Special thanks to BioLion! You're awesome :D***)
#!/usr/bin/perl use warnings; # Perl interpreter command use strict; my %bow1 = (); my $file1 = shift; open (FILE1, "$file1")|| die "Failed to open $file1 for reading : $!"; + # Open first file while (<FILE1>) { # Reading first hash my ($ID, undef, undef, undef, $Seq) = split; $bow1{$ID}[0] = $ID; $bow1{$ID}[1] = $Seq; } close FILE1 || die "Failed to close $file1 : $!"; my %bow2 = (); my $file2 = shift; open (FILE2, "$file2") || die "Failed to open $file2 for reading : $!" +; # Open first file while (<FILE2>) { # Reading second hash my ($ID, undef, undef, undef, $Seq) = split; $bow2{$ID}[0] = $ID; $bow2{$ID}[1] = $Seq; } close FILE2 || die "Failed to close $file2 : $!"; print"Match status\t$file1 ID\t$file1 Sequence\t$file2 ID\t$file2 Sequ +ence\n"; # Print title my $totalCount=0; #initialize variables for counting my $identical=0; my $diffSeq=0; my $unique=0; foreach my $ID (keys %bow1){ # can use (sort keys %hash) to put items +in a specified order if (exists $bow2{$ID}[0] ){ if ( $bow1{$ID}[0] eq $bow2{$ID}[0] ){ ## id and sequence are stored as key value pairs if ( $bow1{$ID}[1] eq $bow2{$ID}[1] ){ #print "Identical\t$bow1{$ID}[0]\t$bow1{$ID}[1]\t$bow2{$ID}[0 +]\t$bow2{$ID}[1]\n"; #display ID and sequences -->too many: commente +d out $identical=$identical+1; #count identical pairs } else{ print "SameID, DiffSeq\t$bow1{$ID}[0]\t$bow1{$ID}[1]\t$bow2{$I +D}[0]\t$bow2{$ID}[1]\n"; #display ID and sequences $diffSeq=$diffSeq+1; #count pairs with different sequences but + identical IDs } } } else { print "Unique\t$bow1{$ID}[0]\t$bow1{$ID}[1]\t - \t - \n"; #display + ID and sequences $unique=$unique+1; #count unique IDs from first file } } $totalCount = $identical + $diffSeq + $unique; #total count - should m +atch with total ID in first file print "Identical\tSeq is different\tUnique in $file1\tTotal\n"; #print + title print "$identical\t$diffSeq\t$unique\t$totalCount\n"; #print numbers exit;

In reply to UPDATE! I fixed it :D by FluffyBunny
in thread how to compare two hashes with perl? by FluffyBunny

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.