in reply to Compare 2 Hashes w/ Multiple Variables
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:
- 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:$hash1{$key}= "$metric1;$metric2;$metric3";
No need for %hash2, no need to store the file in an array.print $name2, $hash{$name2}, ";", $metric4, "\n" if exists $hash{$name +2};
Also, I have not seen your input data, but this code:
could be replaced by something much simpler like this:$line1 =~ /(.*?)\,(.*?)\,(.*?)\,(.*?)\,(.*?)\,(.*)/; $description1 = $1; $cktsizetemp1 = $2; $bits1 = $3; # print "$3\n"; $availability1 = sprintf("%.2f", $4); $bitsin1 = $5; $bitsout1 = $6;
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.my ($description1, $cktsizetemp1, $bits1, $availability1, $bitsin1, $b +itsout1) = split /,/, $line1; $availability1 = sprintf("%.2f", $availability);
Please provide a sample of your input data (file1 and file2) if you need further detailed help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Compare 2 Hashes w/ Multiple Variables
by Tanktalus (Canon) on Dec 24, 2013 at 17:28 UTC | |
by Laurent_R (Canon) on Dec 24, 2013 at 18:07 UTC |