in reply to Re: Trouble iterating through a hash
in thread Trouble iterating through a hash

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";