Hi ahjohnson2,

OK, now you have added your code. What you are doing is far far too complicated. What you need to do is this:

- Read file1 and, for each line, find the name (the key) and the three metrics, and store in your hash something like this:

$hash1{$key}= "$metric1;$metric2;$metric3";
- Then, you read file2 line by line, split each line to find the name2 and mtric4. Once you have that, check is the name2 is an existing key of %hash1, and, if such is the case, just print the output with something like this:
print $name2, $hash{$name2}, ";", $metric4, "\n" if exists $hash{$name +2};
No need for %hash2, no need to store the file in an array.

Also, I have not seen your input data, but this code:

$line1 =~ /(.*?)\,(.*?)\,(.*?)\,(.*?)\,(.*?)\,(.*)/; $description1 = $1; $cktsizetemp1 = $2; $bits1 = $3; # print "$3\n"; $availability1 = sprintf("%.2f", $4); $bitsin1 = $5; $bitsout1 = $6;
could be replaced by something much simpler like this:
my ($description1, $cktsizetemp1, $bits1, $availability1, $bitsin1, $b +itsout1) = split /,/, $line1; $availability1 = sprintf("%.2f", $availability);
Finally, I would suggest that you use strict; and use warnings; near the top of your program and declare your variables with the my function.

Please provide a sample of your input data (file1 and file2) if you need further detailed help.


In reply to Re: Compare 2 Hashes w/ Multiple Variables by Laurent_R
in thread Compare 2 Hashes w/ Multiple Variables by ahjohnson2

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.