You may be interested in Set::Scalar for doing set memberships (determining of @a is a subset of @b for example), but that may be a bit much, since apparently you have to build set objects out of your data; you can't just do set membership functions on the arrays themselves.

I also have a tickling in the back of my brain about the possibility that there's a module out there specifically for recursing down data structures and determining if two of them are equal. I'll see if I can find such a thing and I'll update this post if I do. If someone else finds something like that, please let us know.

Update: Found it. Data::Compare is what you want. Also, my code below will return true even if your arrays are in different orders, since it's incorrectly examining the presence of each item, and not the true structure of the array. Use Data::Compare.

Otherwise, this code might do what you're looking for:

use strict; sub hash_equality (\%\%) { my %hash1 = %{shift()}; my %hash2 = %{shift()}; my %done; foreach my $key (keys %hash1, keys %hash2) { next if $done{$key}++; if (!ref($hash1{$key})) { return if $hash1{$key} ne $hash2{$key}; } elsif (ref($hash1{$key}) eq "ARRAY") { my ($e, %union, %isect); foreach $e (@{$hash1{$key}}, @{$hash2{$key}}) { $union{$e}++ && $isect{$e}++; } return if scalar(keys %union) != scalar(keys %isect); } else { # handle other reference types if needed? return; } } # ok return 1; } my %A = ( one => 1, two => [ qw{ t w o } ] ); my %B = ( one => 1, two => [ qw{ t r e } ] ); my %C = ( one => 1, two => [ qw{ t w o } ] ); print "Mismatch!\n" unless hash_equality(%A, %B); print "OK!\n" if hash_equality(%A, %C);

In reply to Re: Searching out values in Hash by Fastolfe
in thread Searching out values in Hash by Lord Rau

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.