Reverse the hash and use function each to get each pair
%presidents = ( George => "A",
Abe => "B",
Thomas => "C",
Harry => "D" );
@keys = keys( %presidents );
@values = values( %presidents );
print "%presidents with its keys and values reversed\n";
%hash = reverse( %presidents );
while ( ( $key, $value ) = each( %presidents ) ) {
print "$key => $value\n";
}
Related examples in the same category