in reply to Re: Bi-Directional Hash Lookup
in thread Bi-Directional Hash Lookup

I had thought of this too, but the OP claimed that each of the keys and the values are unique. He didn't exclude that any of the keys may also be a value, although it is definitely reasonable to doubt about this. I'm pointing this out just to let him/her know that this solution may fail in the case it is so:
use Data::Dumper; my %hash=(foo => 'bar', bar => 'baz'); %hash=(%hash, reverse %hash); print Dumper \%hash;

Incidentally I wouldn't have used your smart and elegant syntax -of which I may have thought, but but which didn't occur to me- and I would have done a clumsier

@hash{values %hash} = keys %hash;
instead.

Replies are listed 'Best First'.
Re^3: Bi-Directional Hash Lookup
by thor (Priest) on Oct 11, 2005 at 14:48 UTC
    He didn't exclude that any of the keys may also be a value, although it is definitely reasonable to doubt about this.
    I took the OP to mean that each value would be unique in the hash. That is to say that for any key or value in the hash, there would not exist any other key or value that would have the same..erm...value.

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come