http://qs321.pair.com?node_id=838578

jimbass has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone, I'm obviously new and have a problem understanding the right tool to use to make mathematical comparisons between the values of two different hashes that (should) have the same keys.

I have many point to multi-point radios at work, and the signal strengths can be tested by using telnet. I hacked a script together using expect to get on the radios in question and run the tests, then used shell tools like grep and cut to get the data reduced to just what (I think) I need.

The data ends up in a hash, and it has this form:

%hash1 = ("1", "20", "2", "20", "4", "19", "5", "20", "6", "18"); %hash2 = ("1", "19", "2", "20", "4", "16", "5", "19", "6", "20");

I've read through google about tools (Data::Compare) that will compare the entire hash and report if they are identical or not, but that isn't what I'm looking to do. I know that except for one time in 1000, %hash1 and %hash2 won't be identical.

What I'm looking to accomplish is to have perl look at each key/value in the first hash, and simply compare it to the same key/value in the second.

The results I'd like to see based on the example above is something like:

1 (20-19)=1 2 (20-20)=0 4 (19-16)=3 5 (20-19)=1 6 (18-20)=-2

What I'm not grasping is how to get perl to compare the individual key->value to the second key->value.

I probably made it seem like I'm looking for the output to be a 3rd hash. That wouldn't be bad, but it also isn't necessary, all I need is the difference in scores. The examples are real values, everything in the hashes are numbers, there aren't any strings. The numbers do get a bit uglier (the second hash is made up of the averages of several tests).

Its also distinctly possible that I'm going about this in completely the wrong way, and if so please point me in the right direction!

Thanks!