Reverse a hash : reverse « Hash « Perl






Reverse a hash

   


#!/usr/bin/perl -w

use strict;

my %where = (
    A     => "AA",
    B     => "BB",
    C      => "CC",
    D => "DD"
);

my %who = reverse %where;

foreach (keys %who) {
    print "in $_ lives $who{$_}\n";
}

   
    
    
  








Related examples in the same category

1.Reverse a hash: use key as the value, and value as the key
2.Reverse the hash and use function each to get each pair
3.Reverse the key and value