An issue is that push @{ $data{$taxon} }, $3; does not make sense - you intimate that data is a hash of hash, but you are using it as a hash of array in that statement.

Without more information telling us what you want to do with the data it's not clear if the data structures you are generating are appropriate. Consider the following sample however:

use strict; use warnings; my $file1 = <<FILE; dna: species_1 ACCATGATACGATG species_2 GGTTTCGACGCAGA species_3 GGACTCAGCGACTA FILE my $file2 = <<FILE; morph: species_1 001001010201001001 species_2 002010200210120201 species_4 001001110000000101 species_5 111001001001000201 FILE my %data; my $dnaLen = 0; my $morphLen = 0; open IN, '<', \$file1 or die "Failed to open file1: $!"; while (<IN>) { next unless /(^\w+)\s+(\w+)/; $data{$1}{dna} = $2; $dnaLen ||= length $2; } close IN; open IN, '<', \$file2 or die "Failed to open file2: $!"; while (<IN>) { next unless /(^\w+)\s+(\w+)/; $data{$1}{morph} = $2; $morphLen ||= length $2; } close IN; die "No dna data found" unless $dnaLen; die "No morph data found" unless $morphLen; for my $species (sort keys %data) { $data{$species}{dna} ||= '?' x $dnaLen; $data{$species}{morph} ||= '?' x $morphLen; print "$species: $data{$species}{dna}$data{$species}{morph}\n"; }

Prints:

species_1: ACCATGATACGATG001001010201001001 species_2: GGTTTCGACGCAGA002010200210120201 species_3: GGACTCAGCGACTA?????????????????? species_4: ??????????????001001110000000101 species_5: ??????????????111001001001000201

which uses a hash of hash where the primary key is the species and the secondary key is morph or dna.


Perl is environmentally friendly - it saves trees

In reply to Re: Combining hashes of hahses? by GrandFather
in thread Combining hashes of hahses? by erio

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.