Using the print method of Text::CSV_XS, eliminating $hash2 totally, and eliminating the {info1} level instead just assigning an array ref to $hash1->{$ID}.

#!/usr/bin/perl use warnings; use strict; use diagnostics; my $hash1; use Text::CSV_XS; my $sep="\t"; my $csv = Text::CSV_XS->new ({ sep_char => $sep }); open (my $file1, "<","wholepedigree_F.txt") or die "Couldn't open whol +epedigree_F.txt \n"; while (my $row = $csv->getline ($file1)) { next if ($.==1); my ($ID, $sire, $dam, $F, $FB, $AHC, $FA) = @$row; if ($ID){ $hash1 -> {$ID}= [$F,$AHC]; } } close $file1; my $Output=\*STDOUT; open (my $file2, "<","damF.txt") or die "Couldn't open damF.txt\n"; while (my $row = $csv->getline ($file2)) { next if ($.==1); my ($damID, $damF, $damAHC, $prog) = @$row; if ($prog && ($hash1->{$prog})) { my $status = $csv->print($Output, [$prog,@{$hash1->{$prog}},$da +mID,$damF,$damAHC]); print "\n"; } } close $file2; print "Done";


In reply to Re^2: Trouble iterating through a hash by huck
in thread Trouble iterating through a hash by e9292

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.