Yes, @v1, @v2 etc .. would be permutation of others. The 'difference' between 2 same key-valued hashes is the total number of keys in a hash - total number of common keys-value pairs between two hashes.

It sounds like you might actually be trying to cluster the hashes based on relative similarity to each other -- or maybe you just want to identify the two hashes that are most similar to each other.

Anyway, it might be interesting to treat the key-value pairs as strings, print the contents of each hash as a sorted list of these strings, then do pair-wise diffs on the text files. The pair with the fewest diffs is the closest match. The following has not been tested, but perhaps it will be useful.

sub printHash { my ( $hash_name, $hash_ref ) = @_; open( LIST, ">", $hash_name ) or die $!; print LIST sort map { "$_ $$hash_ref{$_}\n" } keys %$hash_ref; close LIST; } ... # assume you have an "ur-hash", holding hash_refs keyed by hash_name: my @difflist1 = my @difflist2 = sort keys %all_hashes; foreach my $name ( keys %all_hashes ) { printHash( $name, $all_hashes{$name} ); } my %distances; foreach my $h1 ( @difflist1 ) { shift @difflist2; # dispose of the identical item in list2 foreach my $h2 ( @difflist2 ) { $distances{"$h1:$h2"} = `diff $h1 $h2 | grep -c '^<>'`; } } # then do something with the values in %distances

(update: fixed to read $$hash_ref{$_} in the subroutine)


In reply to Re: Re: The Best Hash by graff
in thread The Best Hash by artist

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.