Here's one way to do it. I'm creating a hash of hashes, where the elements of the inner hash are array references (so a hash of arrays). This means that for vgs that all have the same maj_num, the hash should only have one key, whereas if the maj_nums are different, there's more than one key. The output generation uses join, map, and de-referencing operations (see perlreftut and perlref).

use warnings; use strict; use Data::Dump; # debug my @vgmap = ( { node => "node1", vg => "vg1", maj_num => 36 }, { node => "node2", vg => "vg1", maj_num => 36 }, { node => "node1", vg => "vg2", maj_num => 37 }, { node => "node2", vg => "vg2", maj_num => 37 }, { node => "node1", vg => "vg3", maj_num => 38 }, { node => "node2", vg => "vg3", maj_num => 40 }, ); my %vgmap; for my $vgm (@vgmap) { push @{ $vgmap{ $vgm->{vg} }{ $vgm->{maj_num} } }, $vgm->{node}; } dd \%vgmap; # debug for my $vg (sort keys %vgmap) { my @maj_nums = sort keys %{ $vgmap{$vg} }; if ( @maj_nums != 1 ) { print "$vg: ", join( "; ", map { "$_ used on " . join ", ", @{ $vgmap{$vg}{$_}} } @maj_nums ), "\n"; } } __END__ { vg1 => { 36 => ["node1", "node2"] }, vg2 => { 37 => ["node1", "node2"] }, vg3 => { 38 => ["node1"], 40 => ["node2"] }, } vg3: 38 used on node1; 40 used on node2

In reply to Re: Compare the values in the hash by haukex
in thread Compare the values in the hash by perl_5eeker

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.