Skip navigation.
Your source for Perl tips, howto's, faq and tutorials
( categories: )

Use reverse to invert a hash.

%inverted = reverse %hash;


  • If the original hash has duplicated values (more than one key is mapped to the same value) then the reversed hash will have fewer elements, because the duplicated value will only map to only one of the keys.
  • This operation can be very expensive in terms of processing time and memory usage if the hash to be inverted is very large.