in reply to sorting and comparing hashes
You don't actually want to sort two hashes. No really, you said so. You want to compare two hashes. As you say, if a human is comparing them it is easier if they are sorted. But not if the computer is going to do it for you.
Your longer term goal basically wants to take two hashes (%first and %second) as input and list:
You can get the @additions or @deletions by looping through the keys of one hash and doing 'exists' test on the other. The situation is symettric and so you can write that bit as a helper routine and call it twice.
You can get modifications by looping through the keys of either hash (not both) and doing nothing in the loop if the key is in either of the @additions or @deletions arrays. (You might want to invert the arrays into hashes to make an efficient "is this scalar in this array" test.)
But you don't need the keys sorted in any of the loops described above.
Have fun.
PS. If efficency is your goal you can reduce the number of loops in what I have described above. But hey, optimising pseudo-code-written-in-english could be called premature.
|
|---|