in reply to Compare Hashes and Arrays
For arrays you could compute the intersection, and if the size of the intersection array is the same size as both input arrays, then they are identical. List::Compare can be used for getting the intersection.
You could have your own compare() subroutine which directs to the corret comparison depending on what sort of data is passed and how you want to define 'the same'.
I didn't find any problem when comparing with hashes where in keys are in whatever order. I accept that my understanding is wrong and certainly it should not matchActually the two hashes you give *are* the same. Hash key/value pairs are not stored in the order they are input, and your key/value pairs are the same...
I haven't had much time to look into the pros/cons of it yet, and i don't know how uesful it might be, but as of 5.10 (i think, at least my 5.8.8 doesn't have the feature) the ~~ smartmatch operator can compare hashes and arrays ( perlfaq4 ), although it seems to have the same issues about ordering of elements as OP and rata have already mentioned...
As usual, it is all a matter of semantics, and 'identical' can be defined several ways, so like i said, i would have my own little sub that does exactly what *i* define as identical. HTH.
|
|---|