in reply to Re^2: Compare array of hashes
in thread Compare array of hashes

++AnishaM: Good progress. From reading your original question, the results you show are what I thought you wanted. Given that you don't seem happy with those results, here are further ideas

but it compares each key of every Hash in structure1 with each key of every Hash in structure2

friendly pedant mode: Technically, for every row (subhash) of the first array and for every row (subhash) of the second array, you are comparing the value of each key in the first subhash to the value of the same key of the second subhash, for a total of 5*5*3=75 comparisons. If you were really comparing the value of every key of each subhash (ie, comparing name to 'name', 'time', and 'place', etc), it would be 5*5*3*3=225 comparisons.

If you really only want to compare the first row of HOAOH1 with the first row of HOAOH2, the second row with the second row, etc (for a total of 5 outer comparisons and 3 key comparisons = 25), here's a hint: since you want the row# to match for each subhash that's compared, you might want to collapse the arrayItem1 and arrayItem2 loops into a single loop that gives an index, and then use that index to find the appropriate row from each HOAOH#

I would also recommend printing something during the FALSE condition of your compare, as well, so that you can see better what's going on and how many loops are being executed. You might want to add the outer loop variables to your print statements (whether they be references, indexes, or what have you), so that way you can tell exactly which pairs are being compared.


update 1: reword the pedant-mode to be more pedantically correct (100% correctness not guaranteed). :-)

update 2: fix brackets to parenthesis in update 1