I want to compare the genotypes of two hashes when the chromosome and position match.

Within one hash, is it possible for two or more records to have the same chromosome and position? If not, you might change your underlying record structure to a hash of genotypes, keyed by a merged string of chromosome and position. Something like this:

$gen_seq_list{'42-MG-BA'} = ( '19_35770059' => 'TC', '2_68019584' => 'G', '16_9561557' => 'G' );

And then perhaps:

for my $seq (keys %$gen_seq_list) { for (keys %{$seq}) { if ($gen_seq_list{$seq}{$_} == $cave_snp_list{$seq}{$_}) { ... } } }

Another thought is to build one hash instead of two like this:

use strict; use warnings; my %genes = ( '42-MG-BA' => { '19_35770059' => { cave => 'TC', gen => 'AA' }, '2_68019584' => { cave => 'G' }, '16_9561557' => { gen => 'AG' }, }, '41-OK-DZ' => { '7_158773210' => { gen => 'AA', cave => 'G'}, }, ); for my $gene (keys %genes) { for my $seq (keys %{$genes{$gene}}) { my $href = \%{$genes{$gene}{$seq}}; if (keys %$href > 1) { print "$gene:$seq:", join(",", map {"$_=$$href{$_}"} keys %$href), "\n"; } } } __OUTPUT__ 41-OK-DZ:7_158773210:gen=AA,cave=G 42-MG-BA:19_35770059:gen=AA,cave=TC

In reply to Re: comparing values of o hashes by hbm
in thread comparing values of o hashes by Anonymous Monk

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.