Hi everyone, I am trying to merge common values between two files and print out the relevant information. I am using a code I have used many times to merge files, and for some reason it isn't working. There seems to be a problem with calling out the first hash in the second part of the script- but it should work with the global variables declared. The format of the input files are: damF.txt
501093 0 0 3162 2958 0 0 3163 1895 0 0 3164 1382 0 0 3165 2869 0 0 3166
wholepedigree_F.txt
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
I want the output to match column 4 of damF.txt and wholepedigree_F.txt and print columns 3 and 5 of whole_pedigree and columns 1,2,3 of damF.txt. this is the code:
#!/usr/bin/perl use warnings; use strict; use diagnostics; use vars qw($ID $sire $dam $F $AHC $FB $FA $hash1 %hash1 $info1 $damID + $damF $damAHC $prog $hash2 %hash2 $info2); open (FILE1, "<wholepedigree_F.txt") or die "Couldn't open wholepedigr +ee_F.txt\n"; my $N = 1; while (<FILE1>){ chomp (my $line=$_); next if 1..$N==$.; my ($ID, $sire, $dam, $F, $FB, $AHC, $FA) = split (/\t/, $line); if ($ID){ $hash1 -> {$ID} -> {info1} = "$F\t$AHC"; } } close FILE1; open (FILE2, "<damF.txt") or die "Can't open damF.txt \n"; open (Output, ">output.txt") or die "Can't Open output file"; print Output "\n"; while (<FILE2>) { chomp (my $line=$_); next if 1..$N==$.; my ($damID, $damF, $damAHC, $prog) = split (/\t/, $line); if ($prog){ $hash2 -> {$prog} -> {info2} = "$damID\t$damF\t$damAHC"; } if ($prog && ($hash1->{$ID})) { $info1 = $hash1 -> {$ID} -> {info1}; $info2 = $hash2 -> {$prog} -> {info2}; print "$ID\t$info1\t$info2\n"; } } close Output; close FILE2; print "Done";
Please note that the input files have about 500000 entries in each column. Please help! Thanks in advance!

In reply to 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.