in reply to Re: Comparing elements in Array of Hashes (AoH)
in thread Comparing elements in Array of Hashes (AoH)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Comparing elements in Array of Hashes (AoH)
by tobyink (Canon) on Jul 18, 2012 at 14:29 UTC | |
OK then, the outer arrays are essentially the wrong structure for doing a comparison - you'd be better off with hashes of hashes. But perhaps the outer arrays make sense in other parts of your code, so let's stick with them and just convert to hash temporarily while doing the comparison. The following example copies both sets of data into a temporary hash to make the comparisons a bit easier. It should run in roughly O(n) time. In other words, the amount of time it takes to run should increase linearly (rather than quadratically or exponentially) with the number of items being processed. Of course, building the temporary hash structure uses up extra memory. You're trading memory for CPU time.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] |