in reply to Question about fast switch hash key-value pairs.

Your code is fine.

Another way is to use a hash slice, using values to get the keys and keys to get the values.

Yet another way is to assign one hash to the other while using reverse.

All of these methods assumes the values are unique.

Update: Added last solution.

Replies are listed 'Best First'.
Re^2: Question about fast switch hash key-value pairs.
by Erez (Priest) on Apr 03, 2008 at 06:46 UTC

    All of these methods assumes the values are unique.

    You might want to add an if exists check in case the values are not unique, and perhaps add the duplicate values to an anonymous inner array (see HASHES OF ARRAYS).

    Software speaks in tongues of man.
    Stop saying 'script'. Stop saying 'line-noise'.
    We have nothing to lose but our metaphors.