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' ] };

In reply to Re: compare an array of hashes by leocharre
in thread compare an array of hashes by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.