I think the nested file reads are getting in your way. First you read a line from DATA, then you read all of KEY, a line at a time. Then you read another line from DATA. Since you've already read all of KEY, you can't read anymore. Only the keys matching the first line in DATA will be processed.

Seems to me that a better approach is to read all of DATA into an array of hashes, then loop through KEY, but I'm fuzzy on what you're trying to accomplish.

Oh, and you've just reinvented arrays the hard way. Consider this instead:

while(<DATA>) { my @c = split / /, $_; # ... }

In reply to Re: How to compare a field in 2 files and set a value if it matches? by chromatic
in thread How to compare a field in 2 files and set a value if it matches? by aschroh

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.