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.
# Some example data...
my @curr = (
{
node => 'Alice',
link => 'A to B',
load => 20,
},
{
node => 'Alice',
link => 'A to C',
load => 24,
},
{
node => 'Bob',
link => 'B to C',
load => 12,
},
{
node => 'Bob',
link => 'B to A',
load => 3,
},
{
node => 'Carol',
link => 'C to A',
load => 14,
},
{
node => 'Carol',
link => 'C to B',
load => 7,
},
);
my @prev = (
{
node => 'Alice',
link => 'A to B',
load => 20,
},
{
node => 'Alice',
link => 'A to C',
load => 24,
},
{
node => 'Bob',
link => 'B to C',
load => 15,
},
{
node => 'Bob',
link => 'B to A',
load => 3,
},
{
node => 'Carol',
link => 'C to A',
load => 12,
},
{
node => 'Carol',
link => 'C to B',
load => 3,
},
);
# Transform to a hash. This happens in roughly O(n) time.
my %hash;
$hash{"$_->{node}|$_->{link}"} = +{%$_} for @curr;
$hash{"$_->{node}|$_->{link}"}{prev_load} = $_->{load} for @prev;
# Again, looping through the hash values is roughly O(n).
for (values %hash)
{
printf
"Node '%s', link '%s': previously %d, currently %d.\n",
$_->{node},
$_->{link},
$_->{prev_load},
$_->{load},
unless $_->{load} == $_->{prev_load};
}
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
|