Is this going in the right direction for you?
Sounds like you just need a HoA (Hash of Array).
#!/usr/bin/perl -w
use strict;
use Data::Dump qw(pp);
my %h=( a=>123, b=>123, c=>12);
print pp \%h; #{ a => 123, b => 123, c => 12 }
print "\n";
# Access each key's value in the %h hash...
#
# Each "new key" in the reversed hash is a
# unique value from the %h hash, i.e., $hash{$key}
#
# But each one of these new "keys" can contain
# multiple values, so that means that the
# reversed hash has to be a more complex data
# structure, a hash of pointers to array...
#
# Each one of the keys of the "reversed hash" is
# a value from the original hash. They now become keys
# of that "reversed hash" and they have as a value,
# a reference to an array of the keys of the original hash.
my %reversed;
foreach my $key (keys %h)
{
# the value of $h{$key} is the new key
# could have been:
# my $new_key = $h{$key};
# push @{$reversed{$new_key}}, $key;
# but this is the same...
push @{$reversed{$h{$key}}}, $key;
}
print pp \%reversed; #{ 12 => ["c"], 123 => ["a", "b"] }
print "\n";
__END__
{ a => 123, b => 123, c => 12 }
{ 12 => ["c"], 123 => ["a", "b"] }
Update: We are very far from needing MD5 keys. I am responding to your clarification of what you want for the output. Please respond to my post with other details if I didn't get it right...And I don't see that this has to do with maximum key length (which is pretty much unlimited). |