Comparison of 2 hashes in perl

0

I have 2 hash tables, the 2 tables have the same keys, but different values.

I need to compare both values of the same key and know the difference in values.

Example:

Hash 1: clave1 = > 5

Hash 1: clave2 = > 10

Hash 2: clave1 = > 9

Hash 2: clave2 = > 4

Difference in values of key1 = 4

Difference of values of the key2 = 6

Thanks in advance!

    
asked by Emmanuel Molina 14.08.2018 в 02:46
source

1 answer

0

You have to loop, say, the first hash, using the keys () function. For example, inside a for ().

Inside the loop, you do an if () to see if it exists (with exists ()) the same entry but in the second hash. In that case, you take the two values of the two hashes, you get the difference and the samples.

    
answered by 14.08.2018 / 05:06
source