in reply to Trouble iterating through a hash
I started re-writing your code, but could not proceed to a final solution due to the above. However this code below may help you.
Some comments to your code:
#!/usr/bin/perl use warnings; use strict; use diagnostics; my %hash; #$damID, $damF, $damAHC, $prog my $damF = <<END; 501093 0 0 3162 2958 0 0 3163 1895 0 0 3164 1382 0 0 3165 2869 0 0 3166 END #$ID, $sire, $dam, $F, $FB, $AHC, $FA my $wholepedigree_F = <<END; 3162 2159 501093 0 0 0 0 3163 2960 2958 0 0 0 0 3164 2269 1895 0 0 0 0 3165 1393 1382 0 0 0 0 3166 2881 2869 0 0 0 0 END open (FILE1, '<', \$wholepedigree_F) or die "Couldn't open wholepedigr +ee_F.txt"; while (my $line = <FILE1>) { chomp $line; next unless $line =~ /\S/; #skip blank lines my ($ID, $F, $AHC) = (split (/\s+/, $line))[0,3,5]; $hash{$ID} = "$F\t$AHC"; } close FILE1; open (FILE2, '<', \$damF) or die "Can't open damF.txt"; #open (OUT, ">output.txt") or die "Can't Open output file"; #print OUT "\n"; while (my $line = <FILE2>) { chomp $line; next unless $line =~ /\S/; #skip blank lines my ($damID, $damF, $damAHC, $prog) = split (/\s+/, $line); if ($hash{$prog}) { my $info1 = $hash{$prog}; my $info2 = "$damID\t$damF\t$damAHC"; print "$prog\t$info1\t$info2\n"; } } #close OUT; close FILE2; print "Done";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trouble iterating through a hash
by huck (Prior) on Mar 09, 2017 at 05:03 UTC | |
by Marshall (Canon) on Mar 09, 2017 at 05:49 UTC |