in reply to hash with both values and keys unique to each other
If you need to ensure that both hash-keys and hash-values are unique, then you probably need to use two hashes. The second hash should contain an entry for every value that’s been used in the first one: the associated value (in the second hash) doesn’t matter, as we only care whether-or-not the key (in the second hash) exists.
if ( (!exists($$hash1{$key} && (!exists($$hash2{$value}) ) { $$hash1{$key} = $value; $$hash2{$value} = 1; // DON'T CARE } else ... // (KEY AND/OR VALUE IS NOT UNIQUE...)
Note that $$hash{$key} is equivalent to $hash->{$key} ... take your pick.