I don't really understand what in FILE2 is supposed to match with what in FILE1? All non-zero data in FILE1 is in some column in FILE2. You do not show a line in FILE2 that would not "match" and you do not provide a sample "good" output.
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:
- "use vars" does not do what you think and there is absolutely no need for that here.
- I only see the need for a single hash of FILE1 - a second hash is not necessary.
- I have no idea about what you think this $N stuff does?
- There is no need for a multi-dimensional hash here and your syntax to address a simple hash is wrong (don't need the arrows).
#!/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";
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.