in reply to hash with both values and keys unique to each other
Assuming your question is "How to keep the values of a hash unique?", the answer is, well, two hashes:
my (%hash, %rhash); while (<>) { chomp; my ($key, $val) = split(/\t/, $_, 2); next if (exists $hash{$key} or exists $rhash{$val}); $hash{$key} = $val; $rhash{$val} = 1; }
Of course, there will be some manual housekeeping of the second hash. You could make it look nicer by creating an object that mimics a hash.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: hash with both values and keys unique to each other
by perlkhan77 (Acolyte) on Jul 12, 2012 at 19:19 UTC | |
by Anonymous Monk on Jul 12, 2012 at 22:14 UTC |
In Section
Seekers of Perl Wisdom