Tie::Hash::TwoWay will take a list of one-way associations and
transparently create their reverse. For instance, say you have a list
of machines, and a list of classes that each machine belongs to.
Tie::Hash::TwoWay will take the machines, one by one, with an
associated array reference of class names, and build the reverse
mapping of classes to machines. All the mappings are stored as
hashes. You can access the secondary mappings as if they were hash
keys in their own right.
Deleting a key in either the forward or reverse mapping will delete
all its mappings in the other direction as well. If a key has no more
mappings, the key itself is deleted as well. For example, if you
delete machine joe that was in class extra, and there are no other
machines in class extra, that class will be automatically deleted as
Peculiarities, which might be considered bugs:
Duplicate keys, overlapping between the primary and the secondary, are
allowed (for instance, a class named the same as a machine). Fetching
a key, checking for its existence, and deleting it will go to the
primary mapping first and then to the secondary.
The keys of the TwoWay hash are the keys of the primary mapping. The
reverse mapping (which is just a hash reference) can be obtained by
using the scalar operator on the tied hash.
Everything is stored in hashes for faster access, at the expense of