I'm going to solve the problem by creating a rudimentary "digest" of each anonymous hash in each array.
Hash %structures will hold the "digests" as keys to anonymous arrays that will hold where the "digest" came from, what array, and what position.
This will be ugly- the output will be mainly for you- it wouldn't be so useful for code, I suppose- but I really have no idea what you expect as output- it's too vague.
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my @array1 =
(
{
hour => "1",
minute => "30",
flag => "cmd1"
},
{
hour => "1",
minute => "30",
flag => "cmd2"
},
{
hour => "1",
minute => "30",
flag => "cmd3"
}
);
my @array2 = (
{
hour => "1",
minute => "30",
flag => "cmd1"
},
{
hour => "1",
minute => "30",
flag => "cmd2"
},
{
hour => "1",
minute => "30",
flag => "cmd3"
},
{
iamdifferent =>'because',
hour => "1",
minute => "30",
flag => "cmd4"
},
{
iamdifferent =>'because',
hour => "1",
minute => "40",
flag => "cmd6"
},
{
iamdifferent =>'because',
hour => "1",
minute => "40",
flag => "cmd6",
minute => "40"
},
{
a =>'because',
b => "1",
c => "40",
d => "cmd6",
minute => "40"
}
);
# this will hold my hash "digests" as keys to lists of
# what array and position it happened in.
my %structures=();
# the arrays with anon hashes we will analize
my @arrays=(\@array1, \@array2);
my $which_array=0;
for (@arrays){
my $a=$_;
my $anon_hash_position_in_array=0;
for (@{$a}){
my $structure;
for my $k(sort (keys %{$_})){
$structure.=":$k:";
}
my $val= "array$which_array"."_position$anon_hash_position_in_
+array";
push @{$structures{$structure}}, $val;
$anon_hash_position_in_array++;
}
$which_array++;
}
print Dumper(\%structures);
exit;
Output:
$VAR1 = {
':flag::hour::minute:' => [
'array0_position0',
'array0_position1',
'array0_position2',
'array1_position0',
'array1_position1',
'array1_position2'
],
':flag::hour::iamdifferent::minute:' => [
'array1_position3'
+,
'array1_position4'
+,
'array1_position5'
],
':a::b::c::d::minute:' => [
'array1_position6'
]
};
|