Thanks Skeeve, moving the inside loop out worked
once i stopped confusing my key and hash values
below is the final code, a bit clinky but it works
open (LIST1, $list1) or die "cannot open $list1";
open (LIST2, $list2) or die "cannot open $list2";
my %list2key= ();
while ($line1 = <LIST1>)
{
my ($a, $b) = split(/\t/,$line1);
$list2key{$a} = $b;
}
while ($line2 = <LIST2>)
{
#get all the variables for line from LIST2
my ($a, $b, $c, $d, $e, $f) = split(/\t/,$line2);
# do you mean "\t" or \t? are there " in the file?
# This will read your second file once for the
# first line of your first file
# As soon as you have the second line of you first
# file, it will forget about the second file!
# Maybe you should move this loop out of the LIST1-loop
if (exists $list2key{$a})
{
$name = $list2key{$a};
#print out to screen as a test then to a file later
print "$name $b $c $d $e $f\n";
}
}
close LIST2;
close LIST1;
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.